Skip to content
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

Propagate deprecated property through $ref's #6093

Merged
merged 2 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -2844,6 +2844,14 @@ public CodegenProperty fromProperty(String name, Schema p) {

if (p.getDeprecated() != null) {
property.deprecated = p.getDeprecated();
} else if (p.get$ref() != null) {
String ref = ModelUtils.getSimpleRef(p.get$ref());
if (ref != null) {
Schema referencedSchema = ModelUtils.getSchemas(this.openAPI).get(ref);
if (referencedSchema != null && referencedSchema.getDeprecated() != null) {
property.deprecated = referencedSchema.getDeprecated();
}
}
asmundg marked this conversation as resolved.
Show resolved Hide resolved
}
if (p.getReadOnly() != null) {
property.isReadOnly = p.getReadOnly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,19 @@ public void testDeprecatedProperty() {
Assert.assertFalse(codegen.fromProperty("customerCode",(Schema) requestProperties.get("customerCode")).deprecated);
}

@Test
public void testDeprecatedRef() {
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/model-deprecated.yaml");
new InlineModelResolver().flatten(openAPI);
final DefaultCodegen codegen = new DefaultCodegen();
codegen.setOpenAPI(openAPI);

final Map requestProperties = Collections.unmodifiableMap(openAPI.getComponents().getSchemas().get("complex").getProperties());

Assert.assertTrue(codegen.fromProperty("deprecated", (Schema)requestProperties.get("deprecated")).deprecated);
Assert.assertFalse(codegen.fromProperty("current", (Schema)requestProperties.get("current")).deprecated);
}

@Test
public void integerSchemaPropertyAndModelTest() {
OpenAPI openAPI = TestUtils.createOpenAPI();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
openapi: 3.0.1
info:
version: 1.0.0
title: Example
license:
name: MIT
servers:
- url: http://api.example.xyz/v1

components:
schemas:
deprecated:
type: object
deprecated: true
properties:
customerCode:
type: string
example: '0001'
firstName:
type: string
example: 'first'
current:
type: object
properties:
customerCode:
type: string
example: '0001'
firstName:
type: string
example: 'first'
complex:
properties:
deprecated:
$ref: "#/components/schemas/deprecated"
current:
type: boolean