io.swagger.v3.parser.util.SchemaTypeUtil Java Examples
The following examples show how to use
io.swagger.v3.parser.util.SchemaTypeUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SchemaTransformer.java From swagger-brake with Apache License 2.0 | 6 votes |
private Schema transformComposedSchema(ComposedSchema swSchema) { Function<ComposedSchema, List<io.swagger.v3.oas.models.media.Schema>> schemaFunc; if (CollectionUtils.isNotEmpty(swSchema.getAllOf())) { schemaFunc = ComposedSchema::getAllOf; } else if (CollectionUtils.isNotEmpty(swSchema.getOneOf())) { schemaFunc = ComposedSchema::getOneOf; } else if (CollectionUtils.isNotEmpty(swSchema.getAnyOf())) { schemaFunc = ComposedSchema::getAnyOf; } else { throw new IllegalStateException("Composed schema is used that is not allOf, oneOf nor anyOf."); } List<SchemaAttribute> objectAttributes = schemaFunc.apply(swSchema) .stream() .map(this::transformSchema) .map(Schema::getSchemaAttributes) .flatMap(Collection::stream) .collect(toList()); return new Schema.Builder(SchemaTypeUtil.OBJECT_TYPE).schemaAttributes(objectAttributes).build(); }
Example #2
Source File: TypeScriptJqueryClientCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
public TypeScriptJqueryClientCodegen() { super(); modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme)); modelTemplateFiles.put("model.mustache", ".ts"); apiTemplateFiles.put("api.mustache", ".ts"); typeMapping.put("Date", "Date"); apiPackage = "api"; modelPackage = "model"; outputFolder = "generated-code/typescript-jquery"; embeddedTemplateDir = templateDir = "typescript-jquery"; this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json")); this.cliOptions.add(new CliOption(JQUERY_ALREADY_IMPORTED, "When using this in legacy app using mix of typescript and javascript, this will only declare jquery and not import it", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); }
Example #3
Source File: TypeScriptReduxQueryClientCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
public TypeScriptReduxQueryClientCodegen() { super(); // clear import mapping (from default generator) as TS does not use it // at the moment importMapping.clear(); supportsMultipleInheritance = true; outputFolder = "generated-code/typescript-redux-query"; embeddedTemplateDir = templateDir = "typescript-redux-query"; this.apiPackage = "src" + File.separator +"apis"; this.modelPackage = "src" + File.separator + "models"; this.apiTemplateFiles.put("apis.mustache", ".ts"); this.modelTemplateFiles.put("models.mustache", ".ts"); this.addExtraReservedWords(); typeMapping.put("date", "Date"); typeMapping.put("DateTime", "Date"); supportModelPropertyNaming(CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.camelCase); this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json")); this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.TRUE.toString())); }
Example #4
Source File: TypeScriptFetchClientCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
public TypeScriptFetchClientCodegen() { super(); modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme)); // clear import mapping (from default generator) as TS does not use it // at the moment importMapping.clear(); outputFolder = "generated-code/typescript-fetch"; embeddedTemplateDir = templateDir = "typescript-fetch"; this.apiTemplateFiles.put("apis.mustache", ".ts"); this.modelTemplateFiles.put("models.mustache", ".ts"); this.addExtraReservedWords(); typeMapping.put("date", "Date"); typeMapping.put("DateTime", "Date"); supportModelPropertyNaming(CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.camelCase); this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json")); this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER, CodegenConstants.USE_SINGLE_REQUEST_PARAMETER_DESC, SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.TRUE.toString())); this.cliOptions.add(new CliOption(PREFIX_PARAMETER_INTERFACES, "Setting this property to true will generate parameter interface declarations prefixed with API class name to avoid name conflicts.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(TYPESCRIPT_THREE_PLUS, "Setting this property to true will generate TypeScript 3.6+ compatible code.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); }
Example #5
Source File: TypeScriptAxiosClientCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
public TypeScriptAxiosClientCodegen() { super(); modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme)); // clear import mapping (from default generator) as TS does not use it // at the moment importMapping.clear(); outputFolder = "generated-code/typescript-axios"; embeddedTemplateDir = templateDir = "typescript-axios"; this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url of your private npmRepo in the package.json")); this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(SEPARATE_MODELS_AND_API, "Put the model and api in separate folders and in separate classes", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(WITHOUT_PREFIX_ENUMS, "Don't prefix enum names with class names", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); }
Example #6
Source File: TypeScriptRxjsClientCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
public TypeScriptRxjsClientCodegen() { super(); modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme)); outputFolder = "generated-code/typescript-rxjs"; embeddedTemplateDir = templateDir = "typescript-rxjs"; this.apiPackage = "apis"; this.apiTemplateFiles.put("apis.mustache", ".ts"); this.modelPackage = "models"; this.modelTemplateFiles.put("models.mustache", ".ts"); this.addExtraReservedWords(); languageSpecificPrimitives.add("Blob"); typeMapping.put("file", "Blob"); this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json")); this.cliOptions.add(new CliOption(WITH_PROGRESS_SUBSCRIBER, "Setting this property to true will generate API controller methods with support for subscribing to request progress.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); // these are used in the api template for more efficient destructuring this.reservedParamNames.add("headers"); this.reservedParamNames.add("query"); this.reservedParamNames.add("formData"); }
Example #7
Source File: AspNetCoreServerCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
private void setCliOption(CliOption cliOption) throws IllegalArgumentException { if (additionalProperties.containsKey(cliOption.getOpt())) { // TODO Hack - not sure why the empty strings become boolean. Object obj = additionalProperties.get(cliOption.getOpt()); if (!SchemaTypeUtil.BOOLEAN_TYPE.equals(cliOption.getType())) { if (obj instanceof Boolean) { obj = ""; additionalProperties.put(cliOption.getOpt(), obj); } } cliOption.setOptValue(obj.toString()); } else { additionalProperties.put(cliOption.getOpt(), cliOption.getOptValue()); } if (cliOption.getOptValue() == null) { cliOption.setOptValue(cliOption.getDefault()); throw new IllegalArgumentException(cliOption.getOpt() + ": Invalid value '" + additionalProperties.get(cliOption.getOpt()).toString() + "'" + ". " + cliOption.getDescription()); } }
Example #8
Source File: ModelUtils.java From openapi-generator with Apache License 2.0 | 5 votes |
public static boolean isUUIDSchema(Schema schema) { if (schema instanceof UUIDSchema) { return true; } if (SchemaTypeUtil.STRING_TYPE.equals(schema.getType()) && SchemaTypeUtil.UUID_FORMAT.equals(schema.getFormat())) { // format: uuid return true; } return false; }
Example #9
Source File: JavaModelTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with list property") public void listPropertyTest() { final Schema schema = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("urls", new ArraySchema() .items(new StringSchema())) .addRequiredItem("id"); final DefaultCodegen codegen = new JavaClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", schema); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property = cm.vars.get(1); Assert.assertEquals(property.baseName, "urls"); Assert.assertEquals(property.getter, "getUrls"); Assert.assertEquals(property.setter, "setUrls"); Assert.assertEquals(property.dataType, "List<String>"); Assert.assertEquals(property.name, "urls"); Assert.assertEquals(property.defaultValue, "new ArrayList<String>()"); Assert.assertEquals(property.baseType, "List"); Assert.assertEquals(property.containerType, "array"); Assert.assertFalse(property.required); Assert.assertTrue(property.isContainer); }
Example #10
Source File: ModelUtils.java From openapi-generator with Apache License 2.0 | 5 votes |
public static boolean isURISchema(Schema schema) { if (SchemaTypeUtil.STRING_TYPE.equals(schema.getType()) && URI_FORMAT.equals(schema.getFormat())) { // format: uri return true; } return false; }
Example #11
Source File: ModelUtils.java From openapi-generator with Apache License 2.0 | 5 votes |
public static boolean isEmailSchema(Schema schema) { if (schema instanceof EmailSchema) { return true; } if (SchemaTypeUtil.STRING_TYPE.equals(schema.getType()) && SchemaTypeUtil.EMAIL_FORMAT.equals(schema.getFormat())) { // format: email return true; } return false; }
Example #12
Source File: JavaClientCodegenTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test public void arraysInRequestBody() { OpenAPI openAPI = TestUtils.createOpenAPI(); final JavaClientCodegen codegen = new JavaClientCodegen(); codegen.setOpenAPI(openAPI); RequestBody body1 = new RequestBody(); body1.setDescription("A list of ids"); body1.setContent(new Content().addMediaType("application/json", new MediaType().schema(new ArraySchema().items(new StringSchema())))); CodegenParameter codegenParameter1 = codegen.fromRequestBody(body1, new HashSet<String>(), null); Assert.assertEquals(codegenParameter1.description, "A list of ids"); Assert.assertEquals(codegenParameter1.dataType, "List<String>"); Assert.assertEquals(codegenParameter1.baseType, "String"); RequestBody body2 = new RequestBody(); body2.setDescription("A list of list of values"); body2.setContent(new Content().addMediaType("application/json", new MediaType().schema(new ArraySchema().items(new ArraySchema().items(new IntegerSchema()))))); CodegenParameter codegenParameter2 = codegen.fromRequestBody(body2, new HashSet<String>(), null); Assert.assertEquals(codegenParameter2.description, "A list of list of values"); Assert.assertEquals(codegenParameter2.dataType, "List<List<Integer>>"); Assert.assertEquals(codegenParameter2.baseType, "List"); RequestBody body3 = new RequestBody(); body3.setDescription("A list of points"); body3.setContent(new Content().addMediaType("application/json", new MediaType().schema(new ArraySchema().items(new ObjectSchema().$ref("#/components/schemas/Point"))))); ObjectSchema point = new ObjectSchema(); point.addProperties("message", new StringSchema()); point.addProperties("x", new IntegerSchema().format(SchemaTypeUtil.INTEGER32_FORMAT)); point.addProperties("y", new IntegerSchema().format(SchemaTypeUtil.INTEGER32_FORMAT)); CodegenParameter codegenParameter3 = codegen.fromRequestBody(body3, new HashSet<String>(), null); Assert.assertEquals(codegenParameter3.description, "A list of points"); Assert.assertEquals(codegenParameter3.dataType, "List<Point>"); Assert.assertEquals(codegenParameter3.baseType, "Point"); }
Example #13
Source File: JavaModelTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with set property") public void setPropertyTest() { final Schema schema = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("urls", new ArraySchema() .items(new StringSchema()) .uniqueItems(true)) .addRequiredItem("id"); final DefaultCodegen codegen = new JavaClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", schema); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property = cm.vars.get(1); Assert.assertEquals(property.baseName, "urls"); Assert.assertEquals(property.getter, "getUrls"); Assert.assertEquals(property.setter, "setUrls"); Assert.assertEquals(property.dataType, "Set<String>"); Assert.assertEquals(property.name, "urls"); Assert.assertEquals(property.defaultValue, "new LinkedHashSet<String>()"); Assert.assertEquals(property.baseType, "Set"); Assert.assertEquals(property.containerType, "set"); Assert.assertFalse(property.required); Assert.assertTrue(property.isContainer); }
Example #14
Source File: ScalaAkkaClientCodegenTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with list property") public void listPropertyTest() { final Schema model = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("urls", new ArraySchema() .items(new StringSchema())) .addRequiredItem("id"); final DefaultCodegen codegen = new ScalaAkkaClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", model); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); //Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property1 = cm.vars.get(1); Assert.assertEquals(property1.baseName, "urls"); Assert.assertEquals(property1.getter, "getUrls"); Assert.assertEquals(property1.setter, "setUrls"); Assert.assertEquals(property1.dataType, "Seq[String]"); Assert.assertEquals(property1.name, "urls"); Assert.assertEquals(property1.defaultValue, "Seq[String].empty "); Assert.assertEquals(property1.baseType, "Seq"); Assert.assertEquals(property1.containerType, "array"); Assert.assertFalse(property1.required); Assert.assertTrue(property1.isContainer); }
Example #15
Source File: PlantumlDocumentationCodegenTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test public void simpleEntityTest() { final Schema model = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("name", new StringSchema()) .addRequiredItem("id") .addRequiredItem("name"); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); plantumlDocumentationCodegen.setOpenAPI(openAPI); final CodegenModel cm = plantumlDocumentationCodegen.fromModel("sample", model); Map<String, Object> objs = createObjectsMapFor(cm); plantumlDocumentationCodegen.postProcessSupportingFileData(objs); List<Object> entityList = getList(objs, "entities"); Assert.assertFalse(entityList.isEmpty(), "empty entity list"); Map<String, Object> firstEntity = getEntityFromList("Sample", entityList); List<Object> fieldList = getList(firstEntity, "fields"); Assert.assertEquals(fieldList.size(), 2, "size of field list"); Map<String, Object> firstField = (Map<String, Object>)fieldList.get(0); Assert.assertEquals((String)firstField.get("name"), "id"); Assert.assertTrue((boolean)firstField.get("isRequired")); Assert.assertEquals((String)firstField.get("dataType"), "Long"); }
Example #16
Source File: GoModelTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with list property") public void listPropertyTest() { final Schema model = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("urls", new ArraySchema() .items(new StringSchema())) .addRequiredItem("id"); final DefaultCodegen codegen = new GoClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", model); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "id"); Assert.assertEquals(property1.dataType, "int64"); Assert.assertEquals(property1.name, "Id"); Assert.assertNull(property1.defaultValue); Assert.assertEquals(property1.baseType, "int64"); Assert.assertTrue(property1.hasMore); Assert.assertTrue(property1.required); Assert.assertTrue(property1.isPrimitiveType); final CodegenProperty property2 = cm.vars.get(1); Assert.assertEquals(property2.baseName, "urls"); Assert.assertEquals(property2.dataType, "[]string"); Assert.assertEquals(property2.name, "Urls"); Assert.assertEquals(property2.baseType, "array"); Assert.assertFalse(property2.hasMore); Assert.assertEquals(property2.containerType, "array"); Assert.assertFalse(property2.required); Assert.assertTrue(property2.isPrimitiveType); }
Example #17
Source File: PythonTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with list property") public void listPropertyTest() { final Schema model = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("urls", new ArraySchema() .items(new StringSchema())) .addRequiredItem("id"); final DefaultCodegen codegen = new PythonClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", model); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "id"); Assert.assertEquals(property1.dataType, "int"); Assert.assertEquals(property1.name, "id"); Assert.assertNull(property1.defaultValue); Assert.assertEquals(property1.baseType, "int"); Assert.assertTrue(property1.hasMore); Assert.assertTrue(property1.required); Assert.assertTrue(property1.isPrimitiveType); final CodegenProperty property2 = cm.vars.get(1); Assert.assertEquals(property2.baseName, "urls"); Assert.assertEquals(property2.dataType, "list[str]"); Assert.assertEquals(property2.name, "urls"); Assert.assertNull(property2.defaultValue); Assert.assertEquals(property2.baseType, "list"); Assert.assertFalse(property2.hasMore); Assert.assertEquals(property2.containerType, "array"); Assert.assertFalse(property2.required); Assert.assertTrue(property2.isPrimitiveType); Assert.assertTrue(property2.isContainer); }
Example #18
Source File: PythonClientExperimentalTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with list property") public void listPropertyTest() { final Schema model = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("urls", new ArraySchema() .items(new StringSchema())) .addRequiredItem("id"); final DefaultCodegen codegen = new PythonClientExperimentalCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", model); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "sample.Sample"); Assert.assertEquals(cm.description, "a sample model"); Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "id"); Assert.assertEquals(property1.dataType, "int"); Assert.assertEquals(property1.name, "id"); Assert.assertNull(property1.defaultValue); Assert.assertEquals(property1.baseType, "int"); Assert.assertTrue(property1.hasMore); Assert.assertTrue(property1.required); Assert.assertTrue(property1.isPrimitiveType); final CodegenProperty property2 = cm.vars.get(1); Assert.assertEquals(property2.baseName, "urls"); Assert.assertEquals(property2.dataType, "[str]"); Assert.assertEquals(property2.name, "urls"); Assert.assertNull(property2.defaultValue); Assert.assertEquals(property2.baseType, "list"); Assert.assertFalse(property2.hasMore); Assert.assertEquals(property2.containerType, "array"); Assert.assertFalse(property2.required); Assert.assertTrue(property2.isPrimitiveType); Assert.assertTrue(property2.isContainer); }
Example #19
Source File: ScalaHttpClientModelTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with list property") public void listPropertyTest() { final Schema model = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("urls", new ArraySchema() .items(new StringSchema())) .addRequiredItem("id"); final DefaultCodegen codegen = new ScalaHttpClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", model); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); //Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property1 = cm.vars.get(1); Assert.assertEquals(property1.baseName, "urls"); Assert.assertEquals(property1.getter, "getUrls"); Assert.assertEquals(property1.setter, "setUrls"); Assert.assertEquals(property1.dataType, "List[String]"); Assert.assertEquals(property1.name, "urls"); Assert.assertEquals(property1.defaultValue, "new ListBuffer[String]() "); Assert.assertEquals(property1.baseType, "List"); Assert.assertEquals(property1.containerType, "array"); Assert.assertFalse(property1.required); Assert.assertTrue(property1.isContainer); }
Example #20
Source File: CSharpModelTest.java From openapi-generator with Apache License 2.0 | 5 votes |
private Schema getArrayTestSchema() { return new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("examples", new ArraySchema().items(new StringSchema())) .addRequiredItem("id"); }
Example #21
Source File: CSharpModelTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with list property") public void listPropertyTest() { final Schema model = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("urls", new ArraySchema() .items(new StringSchema())) .addRequiredItem("id"); final DefaultCodegen codegen = new CSharpClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", model); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "id"); Assert.assertEquals(property1.dataType, "long"); Assert.assertEquals(property1.name, "Id"); Assert.assertNull(property1.defaultValue); Assert.assertEquals(property1.baseType, "long"); Assert.assertTrue(property1.hasMore); Assert.assertTrue(property1.required); Assert.assertTrue(property1.isPrimitiveType); final CodegenProperty property2 = cm.vars.get(1); Assert.assertEquals(property2.baseName, "urls"); Assert.assertEquals(property2.dataType, "List<string>"); Assert.assertEquals(property2.name, "Urls"); Assert.assertNull(property2.defaultValue); Assert.assertEquals(property2.baseType, "List"); Assert.assertFalse(property2.hasMore); Assert.assertEquals(property2.containerType, "array"); Assert.assertFalse(property2.required); Assert.assertTrue(property2.isPrimitiveType); Assert.assertTrue(property2.isContainer); }
Example #22
Source File: TypeScriptAngularJsModelTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with list property") public void listPropertyTest() { final Schema schema = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("urls", new ArraySchema().items(new StringSchema())) .addRequiredItem("id"); final DefaultCodegen codegen = new TypeScriptAngularJsClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", schema); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "id"); Assert.assertEquals(property1.dataType, "number"); Assert.assertEquals(property1.name, "id"); Assert.assertEquals(property1.defaultValue, "undefined"); Assert.assertEquals(property1.baseType, "number"); Assert.assertTrue(property1.hasMore); Assert.assertTrue(property1.required); final CodegenProperty property2 = cm.vars.get(1); Assert.assertEquals(property2.baseName, "urls"); Assert.assertEquals(property2.dataType, "Array<string>"); Assert.assertEquals(property2.name, "urls"); Assert.assertEquals(property2.baseType, "Array"); Assert.assertFalse(property2.hasMore); Assert.assertFalse(property2.required); }
Example #23
Source File: TypeScriptAngularModelTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with list property") public void listPropertyTest() { final Schema schema = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("urls", new ArraySchema().items(new StringSchema())) .addRequiredItem("id"); final DefaultCodegen codegen = new TypeScriptAngularClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", schema); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "id"); Assert.assertEquals(property1.dataType, "number"); Assert.assertEquals(property1.name, "id"); Assert.assertEquals(property1.defaultValue, "undefined"); Assert.assertEquals(property1.baseType, "number"); Assert.assertTrue(property1.hasMore); Assert.assertTrue(property1.required); Assert.assertFalse(property1.isContainer); final CodegenProperty property2 = cm.vars.get(1); Assert.assertEquals(property2.baseName, "urls"); Assert.assertEquals(property2.dataType, "Array<string>"); Assert.assertEquals(property2.name, "urls"); Assert.assertEquals(property2.baseType, "Array"); Assert.assertFalse(property2.hasMore); Assert.assertFalse(property2.required); }
Example #24
Source File: TypeScriptFetchModelTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with list property") public void listPropertyTest() { final Schema model = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("urls", new ArraySchema().items(new StringSchema())) .addRequiredItem("id"); final DefaultCodegen codegen = new TypeScriptFetchClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", model); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "id"); Assert.assertEquals(property1.dataType, "number"); Assert.assertEquals(property1.name, "id"); Assert.assertEquals(property1.defaultValue, "undefined"); Assert.assertEquals(property1.baseType, "number"); Assert.assertTrue(property1.hasMore); Assert.assertTrue(property1.required); Assert.assertFalse(property1.isContainer); final CodegenProperty property2 = cm.vars.get(1); Assert.assertEquals(property2.baseName, "urls"); Assert.assertEquals(property2.dataType, "Array<string>"); Assert.assertEquals(property2.name, "urls"); Assert.assertEquals(property2.baseType, "Array"); Assert.assertFalse(property2.hasMore); Assert.assertFalse(property2.required); }
Example #25
Source File: TypeScriptNodeModelTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test(description = "convert a model with list property") public void listPropertyTest() { final Schema schema = new Schema() .description("a sample model") .addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)) .addProperties("urls", new ArraySchema().items(new StringSchema())) .addRequiredItem("id"); final DefaultCodegen codegen = new TypeScriptNodeClientCodegen(); OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema); codegen.setOpenAPI(openAPI); final CodegenModel cm = codegen.fromModel("sample", schema); Assert.assertEquals(cm.name, "sample"); Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a sample model"); Assert.assertEquals(cm.vars.size(), 2); final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "id"); Assert.assertEquals(property1.dataType, "number"); Assert.assertEquals(property1.name, "id"); Assert.assertEquals(property1.defaultValue, "undefined"); Assert.assertEquals(property1.baseType, "number"); Assert.assertTrue(property1.hasMore); Assert.assertTrue(property1.required); final CodegenProperty property2 = cm.vars.get(1); Assert.assertEquals(property2.baseName, "urls"); Assert.assertEquals(property2.dataType, "Array<string>"); Assert.assertEquals(property2.name, "urls"); Assert.assertEquals(property2.baseType, "Array"); Assert.assertFalse(property2.hasMore); Assert.assertFalse(property2.required); }
Example #26
Source File: ModelUtils.java From openapi-generator with Apache License 2.0 | 5 votes |
public static boolean isByteArraySchema(Schema schema) { if (schema instanceof ByteArraySchema) { return true; } if (SchemaTypeUtil.STRING_TYPE.equals(schema.getType()) && SchemaTypeUtil.BYTE_FORMAT.equals(schema.getFormat())) { // format: byte return true; } return false; }
Example #27
Source File: TypeScriptInversifyClientCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
public TypeScriptInversifyClientCodegen() { super(); modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme)); this.outputFolder = "generated-code/typescript-inversify"; embeddedTemplateDir = templateDir = "typescript-inversify"; modelTemplateFiles.put("model.mustache", ".ts"); apiTemplateFiles.put("api.service.mustache", ".ts"); languageSpecificPrimitives.add("Blob"); typeMapping.put("file", "Blob"); apiPackage = "api"; modelPackage = "model"; this.reservedWords.add("map"); this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json")); this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(USE_PROMISE, "Setting this property to use promise instead of observable inside every service.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(USE_RXJS6, "Setting this property to use rxjs 6 instead of rxjs 5.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(TAGGED_UNIONS, "Use discriminators to create tagged unions instead of extending interfaces.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); }
Example #28
Source File: CppTizenClientCodegen.java From openapi-generator with Apache License 2.0 | 5 votes |
@Override public String toDefaultValue(Schema p) { if (ModelUtils.isBooleanSchema(p)) { return "bool(false)"; } else if (ModelUtils.isNumberSchema(p)) { if (SchemaTypeUtil.FLOAT_FORMAT.equals(p.getFormat())) { return "float(0)"; } return "double(0)"; } else if (ModelUtils.isIntegerSchema(p)) { if (SchemaTypeUtil.INTEGER64_FORMAT.equals(p.getFormat())) { return "long(0)"; } return "int(0)"; } else if (ModelUtils.isMapSchema(p)) { return "new std::map()"; } else if (ModelUtils.isArraySchema(p)) { return "new std::list()"; } else if (!StringUtils.isEmpty(p.get$ref())) { return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()"; } else if (ModelUtils.isDateSchema(p) || ModelUtils.isDateTimeSchema(p)) { return "null"; } else if (ModelUtils.isStringSchema(p)) { return "std::string()"; } return "null"; }
Example #29
Source File: ModelUtils.java From openapi-generator with Apache License 2.0 | 5 votes |
public static boolean isIntegerSchema(Schema schema) { if (schema instanceof IntegerSchema) { return true; } if (SchemaTypeUtil.INTEGER_TYPE.equals(schema.getType())) { return true; } return false; }
Example #30
Source File: ModelUtils.java From openapi-generator with Apache License 2.0 | 5 votes |
public static boolean isShortSchema(Schema schema) { if (SchemaTypeUtil.INTEGER_TYPE.equals(schema.getType()) // type: integer && SchemaTypeUtil.INTEGER32_FORMAT.equals(schema.getFormat())) { // format: short (int32) return true; } return false; }