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
  • !13199

Fix null ref on invalid requestBody reference (fixes #13197)

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/dillendev/hotfix/null-ref-invalid-requestbody-ref into master 2 years ago
  • Overview 3
  • Commits 1
  • Pipelines 0
  • Changes 3

Created by: dmeijboom

Fix for #13197 (closed)

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 (6.1.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Compare
  • master (base)

and
  • latest version
    41be57f6
    1 commit, 2 years ago

3 files
+ 32
- 6

    Preferences

    File browser
    Compare changes
modules/openap‎i-generator/src‎
main/java/org/ope‎napitools/codegen‎
InlineModelR‎esolver.java‎ +5 -1
te‎st‎
java/org/opena‎pitools/codegen‎
InlineModelRes‎olverTest.java‎ +18 -5
resour‎ces/3_0‎
inline_model_‎resolver.yaml‎ +9 -0
modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java
+ 5
- 1
  • View file @ 41be57f6

  • Edit in single-file editor

  • Open in Web IDE


@@ -167,7 +167,7 @@ public class InlineModelResolver {
* Return true if a model should be generated e.g. object with properties,
* enum, oneOf, allOf, anyOf, etc.
*
* @param schema target schema
* @param schema target schema
* @param visitedSchemas Visited schemas
*/
private boolean isModelNeeded(Schema schema, Set<Schema> visitedSchemas) {
@@ -429,6 +429,10 @@ public class InlineModelResolver {
if (requestBody.get$ref() != null) {
String ref = ModelUtils.getSimpleRef(requestBody.get$ref());
requestBody = openAPI.getComponents().getRequestBodies().get(ref);
if (requestBody == null) {
return;
}
}
flattenContent(requestBody.getContent(),
modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java
+ 18
- 5
  • View file @ 41be57f6

  • Edit in single-file editor

  • Open in Web IDE


@@ -351,6 +351,19 @@ public class InlineModelResolverTest {
assertTrue(user.getProperties().get("city") instanceof StringSchema);
}
@Test
public void resolveRequestBodyInvalidRef() {
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
new InlineModelResolver().flatten(openAPI);
RequestBody requestBodyReference = openAPI
.getPaths()
.get("/resolve_request_body_invalid_ref")
.getPost()
.getRequestBody();
assertNull(requestBodyReference.getContent());
}
@Test
public void resolveInlineRequestBody() {
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
@@ -611,7 +624,7 @@ public class InlineModelResolverTest {
Schema requestBodySchema = ModelUtils.getReferencedSchema(openAPI, mediaType.getSchema());
assertNotNull(requestBodySchema);
assertEquals(1, requestBodySchema.getProperties().size(), 1);
assertTrue(requestBodySchema.getProperties().get("arbitrary_object_request_body_property") instanceof ObjectSchema);
assertTrue(requestBodySchema.getProperties().get("arbitrary_object_request_body_property") instanceof ObjectSchema);
}
@Test
@@ -954,12 +967,12 @@ public class InlineModelResolverTest {
.getContent()
.get("application/json")
.getSchema();
//.getProperties()
//.get("nullable_request_body_property");
//.getProperties()
//.get("nullable_request_body_property");
Schema nullableRequestBodySchema = ModelUtils.getReferencedSchema(openAPI, nullableRequestBodyReference);
//assertEquals(nullableRequestBodySchema, "");
Schema nullableSchema = ModelUtils.getReferencedSchema(openAPI,
((Schema)nullableRequestBodySchema.getProperties().get("nullable_request_body_property")));
((Schema) nullableRequestBodySchema.getProperties().get("nullable_request_body_property")));
assertTrue(nullableSchema.getNullable());
}
@@ -1047,7 +1060,7 @@ public class InlineModelResolverTest {
requestBodyReference.getContent().get("application/json").getSchema().get$ref());
//assertEquals("#/components/schemas/resolveInlineRequestBodyAllOf_request", requestBodyReference.get$ref());
ComposedSchema allOfModel =(ComposedSchema) openAPI.getComponents().getSchemas().get("resolveInlineRequestBodyAllOf_request");
ComposedSchema allOfModel = (ComposedSchema) openAPI.getComponents().getSchemas().get("resolveInlineRequestBodyAllOf_request");
assertEquals("#/components/schemas/resolveInlineRequestBody_request", allOfModel.getAllOf().get(0).get$ref());
//Schema allOfModel = ModelUtils.getReferencedSchema(openAPI, requestBodyReference.get$ref());
modules/openapi-generator/src/test/resources/3_0/inline_model_resolver.yaml
+ 9
- 0
  • View file @ 41be57f6

  • Edit in single-file editor

  • Open in Web IDE


@@ -7,6 +7,14 @@ info:
servers:
- url: http://api.example.xyz/v1
paths:
/resolve_request_body_invalid_ref:
post:
requestBody:
$ref: '#/components/schemas/Invalid'
operationId: resolveRequestBodyInvalidRef
responses:
'200':
description: OK
/resolve_inline_request_body:
post:
requestBody:
@@ -348,6 +356,7 @@ paths:
data:
type: string
components:
requestBodies: {}
schemas:
Users:
type: array
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
3
Feature: Generator Inline Schema Handling Issue: Bug
3
Feature: Generator Inline Schema Handling Issue: Bug
    Assign labels
  • Manage project labels

Milestone
6.1.0
6.1.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
2
2 participants
Administrator
William Cheng
Reference: OpenAPITools/openapi-generator!13199
Source branch: github/fork/dillendev/hotfix/null-ref-invalid-requestbody-ref

Menu

Explore Projects Groups Snippets