Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !11515

[TypeScript] Fix type array with uniqueItems

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/ty-v1/fix-typescript-unique-array-bug into master 3 years ago
  • Overview 0
  • Commits 6
  • Pipelines 0
  • Changes 32

Created by: ty-v1

resolve #10174 (closed).

This PR fixes typescript generator so that it does not generate import of Set when an array with uniqueItems exists.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02)

Compare
  • master (base)

and
  • latest version
    fbcc0f87
    6 commits, 2 years ago

32 files
+ 1373
- 1

    Preferences

    File browser
    Compare changes
bin/c‎onfigs‎
typescript-with-‎unique-items.yaml‎ +4 -0
docs/ge‎nerators‎
typesc‎ript.md‎ +1 -0
modules/openap‎i-generator/src‎
main/java/org/…/‎codegen/languages‎
TypeScriptClie‎ntCodegen.java‎ +4 -1
te‎st‎
java/org/…/cod‎egen/typescript‎
TypeScriptClient‎CodegenTest.java‎ +21 -0
resources/3_‎0/typescript‎
unique_i‎tems.yaml‎ +31 -0
samples/client/…/…/‎…/with-unique-items‎
.openapi-‎generator‎
FI‎LES‎ +24 -0
VER‎SION‎ +1 -0
ap‎is‎
Defaul‎tApi.ts‎ +73 -0
basea‎pi.ts‎ +37 -0
except‎ion.ts‎ +15 -0
au‎th‎
aut‎h.ts‎ +52 -0
ht‎tp‎
htt‎p.ts‎ +236 -0
isomorphi‎c-fetch.ts‎ +32 -0
mod‎els‎
ObjectSer‎ializer.ts‎ +218 -0
Respo‎nse.ts‎ +42 -0
all‎.ts‎ +1 -0
ty‎pes‎
ObjectPa‎ramAPI.ts‎ +27 -0
Observab‎leAPI.ts‎ +45 -0
Promis‎eAPI.ts‎ +31 -0
.giti‎gnore‎ +1 -0
.openapi-gen‎erator-ignore‎ +23 -0
Defaul‎tApi.md‎ +57 -0
READ‎ME.md‎ +30 -0
configur‎ation.ts‎ +66 -0
git_p‎ush.sh‎ +51 -0
inde‎x.ts‎ +11 -0
middle‎ware.ts‎ +66 -0
packag‎e.json‎ +27 -0
rxjsS‎tub.ts‎ +27 -0
serve‎rs.ts‎ +53 -0
tsconf‎ig.json‎ +29 -0
uti‎l.ts‎ +37 -0
bin/configs/typescript-with-unique-items.yaml 0 → 100644
+ 4
- 0
  • View file @ fbcc0f87

  • Edit in single-file editor

  • Open in Web IDE

generatorName: typescript
outputDir: samples/client/others/typescript/builds/with-unique-items
inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript/unique_items.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript
docs/generators/typescript.md
+ 1
- 0
  • View file @ fbcc0f87

  • Edit in single-file editor

  • Open in Web IDE


@@ -66,6 +66,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>Long</li>
<li>Map</li>
<li>Object</li>
<li>Set</li>
<li>String</li>
<li>any</li>
<li>boolean</li>
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java
+ 4
- 1
  • View file @ fbcc0f87

  • Edit in single-file editor

  • Open in Web IDE


@@ -143,7 +143,8 @@ public class TypeScriptClientCodegen extends DefaultCodegen implements CodegenCo
"any",
"File",
"Error",
"Map"
"Map",
"Set"
));
languageGenericTypes = new HashSet<>(Arrays.asList(
@@ -169,6 +170,8 @@ public class TypeScriptClientCodegen extends DefaultCodegen implements CodegenCo
typeMapping.put("integer", "number");
typeMapping.put("Map", "any");
typeMapping.put("map", "any");
typeMapping.put("Set", "Set");
typeMapping.put("set", "Set");
typeMapping.put("date", "string");
typeMapping.put("DateTime", "Date");
typeMapping.put("binary", "any");
modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/TypeScriptClientCodegenTest.java
+ 21
- 0
  • View file @ fbcc0f87

  • Edit in single-file editor

  • Open in Web IDE


@@ -4,7 +4,9 @@ import com.google.common.collect.Sets;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.media.*;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.TestUtils;
import org.openapitools.codegen.languages.TypeScriptClientCodegen;
import org.openapitools.codegen.utils.ModelUtils;
@@ -54,4 +56,23 @@ public class TypeScriptClientCodegenTest {
Assert.assertEquals(operation.imports, Sets.newHashSet("Cat", "Dog"));
}
@Test
public void testArrayWithUniqueItems() {
final Schema uniqueArray = new ArraySchema()
.items(new StringSchema())
.uniqueItems(true);
final Schema model = new ObjectSchema()
.description("an object has an array with uniqueItems")
.addProperties("uniqueArray", uniqueArray)
.addRequiredItem("uniqueArray");
final DefaultCodegen codegen = new TypeScriptClientCodegen();
final OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
codegen.setOpenAPI(openAPI);
final CodegenModel codegenModel = codegen.fromModel("sample", model);
Assert.assertFalse(codegenModel.imports.contains("Set"));
}
}
modules/openapi-generator/src/test/resources/3_0/typescript/unique_items.yaml 0 → 100644
+ 31
- 0
  • View file @ fbcc0f87

  • Edit in single-file editor

  • Open in Web IDE

openapi: 3.0.0
info:
version: 1.0.0
title: Sample for uniqueItems
servers:
- url: http://localhost:3000
paths:
/unique-items:
get:
operationId: unique_items
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Response'
components:
schemas:
Response:
type: object
properties:
non-unique-array:
type: array
items:
type: string
unique-array:
type: array
uniqueItems: true
items:
type: string
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
1
Enhancement: CI/Test
1
Enhancement: CI/Test
    Assign labels
  • Manage project labels

Milestone
3.0.2
3.0.2 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference: OpenAPITools/openapi-generator!319
Source branch: github/fork/ty-v1/fix-typescript-unique-array-bug

Menu

Explore Projects Groups Snippets