forked from loafle/openapi-generator-original
Expose deprecated flag in model template (#5964)
This commit is contained in:
parent
c35f32bf39
commit
fe2f092e7f
@ -74,7 +74,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
|||||||
public Set<String> allMandatory = new TreeSet<String>(); // with parent's required properties
|
public Set<String> allMandatory = new TreeSet<String>(); // with parent's required properties
|
||||||
|
|
||||||
public Set<String> imports = new TreeSet<String>();
|
public Set<String> imports = new TreeSet<String>();
|
||||||
public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArrayModel, hasChildren, isMapModel;
|
public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArrayModel, hasChildren, isMapModel, isDeprecated;
|
||||||
public boolean hasOnlyReadOnly = true; // true if all properties are read-only
|
public boolean hasOnlyReadOnly = true; // true if all properties are read-only
|
||||||
public ExternalDocumentation externalDocumentation;
|
public ExternalDocumentation externalDocumentation;
|
||||||
|
|
||||||
@ -543,6 +543,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
|||||||
isArrayModel == that.isArrayModel &&
|
isArrayModel == that.isArrayModel &&
|
||||||
hasChildren == that.hasChildren &&
|
hasChildren == that.hasChildren &&
|
||||||
isMapModel == that.isMapModel &&
|
isMapModel == that.isMapModel &&
|
||||||
|
isDeprecated == that.isDeprecated &&
|
||||||
hasOnlyReadOnly == that.hasOnlyReadOnly &&
|
hasOnlyReadOnly == that.hasOnlyReadOnly &&
|
||||||
getUniqueItems() == that.getUniqueItems() &&
|
getUniqueItems() == that.getUniqueItems() &&
|
||||||
getExclusiveMinimum() == that.getExclusiveMinimum() &&
|
getExclusiveMinimum() == that.getExclusiveMinimum() &&
|
||||||
@ -609,7 +610,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
|||||||
getVars(), getAllVars(), getRequiredVars(), getOptionalVars(), getReadOnlyVars(), getReadWriteVars(),
|
getVars(), getAllVars(), getRequiredVars(), getOptionalVars(), getReadOnlyVars(), getReadWriteVars(),
|
||||||
getParentVars(), getAllowableValues(), getMandatory(), getAllMandatory(), getImports(), hasVars,
|
getParentVars(), getAllowableValues(), getMandatory(), getAllMandatory(), getImports(), hasVars,
|
||||||
isEmptyVars(), hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArrayModel,
|
isEmptyVars(), hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArrayModel,
|
||||||
hasChildren, isMapModel, hasOnlyReadOnly, getExternalDocumentation(), getVendorExtensions(),
|
hasChildren, isMapModel, isDeprecated, hasOnlyReadOnly, getExternalDocumentation(), getVendorExtensions(),
|
||||||
getAdditionalPropertiesType(), getMaxProperties(), getMinProperties(), getUniqueItems(), getMaxItems(),
|
getAdditionalPropertiesType(), getMaxProperties(), getMinProperties(), getUniqueItems(), getMaxItems(),
|
||||||
getMinItems(), getMaxLength(), getMinLength(), getExclusiveMinimum(), getExclusiveMaximum(), getMinimum(),
|
getMinItems(), getMaxLength(), getMinLength(), getExclusiveMinimum(), getExclusiveMaximum(), getMinimum(),
|
||||||
getMaximum(), getPattern(), getMultipleOf());
|
getMaximum(), getPattern(), getMultipleOf());
|
||||||
@ -673,6 +674,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
|||||||
sb.append(", isArrayModel=").append(isArrayModel);
|
sb.append(", isArrayModel=").append(isArrayModel);
|
||||||
sb.append(", hasChildren=").append(hasChildren);
|
sb.append(", hasChildren=").append(hasChildren);
|
||||||
sb.append(", isMapModel=").append(isMapModel);
|
sb.append(", isMapModel=").append(isMapModel);
|
||||||
|
sb.append(", isDeprecated=").append(isDeprecated);
|
||||||
sb.append(", hasOnlyReadOnly=").append(hasOnlyReadOnly);
|
sb.append(", hasOnlyReadOnly=").append(hasOnlyReadOnly);
|
||||||
sb.append(", externalDocumentation=").append(externalDocumentation);
|
sb.append(", externalDocumentation=").append(externalDocumentation);
|
||||||
sb.append(", vendorExtensions=").append(vendorExtensions);
|
sb.append(", vendorExtensions=").append(vendorExtensions);
|
||||||
|
@ -2117,6 +2117,10 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
|| isAliasOfSimpleTypes(schema)); // check if the unaliased schema is an alias of simple OAS types
|
|| isAliasOfSimpleTypes(schema)); // check if the unaliased schema is an alias of simple OAS types
|
||||||
m.discriminator = createDiscriminator(name, schema);
|
m.discriminator = createDiscriminator(name, schema);
|
||||||
|
|
||||||
|
if (schema.getDeprecated() != null) {
|
||||||
|
m.isDeprecated = schema.getDeprecated();
|
||||||
|
}
|
||||||
|
|
||||||
if (schema.getXml() != null) {
|
if (schema.getXml() != null) {
|
||||||
m.xmlPrefix = schema.getXml().getPrefix();
|
m.xmlPrefix = schema.getXml().getPrefix();
|
||||||
m.xmlNamespace = schema.getXml().getNamespace();
|
m.xmlNamespace = schema.getXml().getNamespace();
|
||||||
|
@ -805,6 +805,19 @@ public class DefaultCodegenTest {
|
|||||||
Assert.assertTrue(property.isNullable);
|
Assert.assertTrue(property.isNullable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeprecatedModel() {
|
||||||
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/component-deprecated.yml");
|
||||||
|
new InlineModelResolver().flatten(openAPI);
|
||||||
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
|
||||||
|
CodegenModel codedenPetModel = codegen.fromModel("Pet", openAPI.getComponents().getSchemas().get("Pet"));
|
||||||
|
Assert.assertTrue(codedenPetModel.isDeprecated);
|
||||||
|
|
||||||
|
CodegenModel codegenFoodModel = codegen.fromModel("Food", openAPI.getComponents().getSchemas().get("Food"));
|
||||||
|
Assert.assertTrue(codegenFoodModel.isDeprecated);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeprecatedProperty() {
|
public void testDeprecatedProperty() {
|
||||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/property-deplicated.yaml");
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/property-deplicated.yaml");
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
openapi: 3.0.1
|
||||||
|
info:
|
||||||
|
version: 1.0.0
|
||||||
|
title: Example
|
||||||
|
license:
|
||||||
|
name: MIT
|
||||||
|
servers:
|
||||||
|
- url: http://api.example.xyz/v1
|
||||||
|
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
Food:
|
||||||
|
deprecated: true
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- dry
|
||||||
|
- wet
|
||||||
|
|
||||||
|
Pet:
|
||||||
|
title: a Pet
|
||||||
|
deprecated: true
|
||||||
|
description: A pet up for adoption
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- name
|
||||||
|
- status
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
example: doggie
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
description: pet status
|
||||||
|
enum:
|
||||||
|
- available
|
||||||
|
- pending
|
||||||
|
- adopted
|
Loading…
x
Reference in New Issue
Block a user