Skip to content

Expose isDeprecated variable to model template #5964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
public Set<String> allMandatory = new TreeSet<String>(); // with parent's required properties

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 ExternalDocumentation externalDocumentation;

Expand Down Expand Up @@ -543,6 +543,7 @@ public boolean equals(Object o) {
isArrayModel == that.isArrayModel &&
hasChildren == that.hasChildren &&
isMapModel == that.isMapModel &&
isDeprecated == that.isDeprecated &&
hasOnlyReadOnly == that.hasOnlyReadOnly &&
getUniqueItems() == that.getUniqueItems() &&
getExclusiveMinimum() == that.getExclusiveMinimum() &&
Expand Down Expand Up @@ -609,7 +610,7 @@ public int hashCode() {
getVars(), getAllVars(), getRequiredVars(), getOptionalVars(), getReadOnlyVars(), getReadWriteVars(),
getParentVars(), getAllowableValues(), getMandatory(), getAllMandatory(), getImports(), hasVars,
isEmptyVars(), hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArrayModel,
hasChildren, isMapModel, hasOnlyReadOnly, getExternalDocumentation(), getVendorExtensions(),
hasChildren, isMapModel, isDeprecated, hasOnlyReadOnly, getExternalDocumentation(), getVendorExtensions(),
getAdditionalPropertiesType(), getMaxProperties(), getMinProperties(), getUniqueItems(), getMaxItems(),
getMinItems(), getMaxLength(), getMinLength(), getExclusiveMinimum(), getExclusiveMaximum(), getMinimum(),
getMaximum(), getPattern(), getMultipleOf());
Expand Down Expand Up @@ -673,6 +674,7 @@ public String toString() {
sb.append(", isArrayModel=").append(isArrayModel);
sb.append(", hasChildren=").append(hasChildren);
sb.append(", isMapModel=").append(isMapModel);
sb.append(", isDeprecated=").append(isDeprecated);
sb.append(", hasOnlyReadOnly=").append(hasOnlyReadOnly);
sb.append(", externalDocumentation=").append(externalDocumentation);
sb.append(", vendorExtensions=").append(vendorExtensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,10 @@ public CodegenModel fromModel(String name, Schema schema) {
|| isAliasOfSimpleTypes(schema)); // check if the unaliased schema is an alias of simple OAS types
m.discriminator = createDiscriminator(name, schema);

if (schema.getDeprecated() != null) {
m.isDeprecated = schema.getDeprecated();
}

if (schema.getXml() != null) {
m.xmlPrefix = schema.getXml().getPrefix();
m.xmlNamespace = schema.getXml().getNamespace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,19 @@ public void testNullableProperty() {
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
public void testDeprecatedProperty() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/property-deplicated.yaml");
Expand Down
Original file line number Diff line number Diff line change
@@ -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