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

Better handling of NPE in parser when referencing invalid schema

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/zhuangheihei/#10321-return-parser-exception-instead-of-npe into master 3 years ago
  • Overview 0
  • Commits 7
  • Pipelines 0
  • Changes 4

Created by: zhuangheihei

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 (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

To close https://github.com/OpenAPITools/openapi-generator/issues/10321

Compare
  • master (base)

and
  • latest version
    32d5c624
    7 commits, 2 years ago

4 files
+ 44
- 2

    Preferences

    File browser
    Compare changes
mod‎ules‎
openapi-generat‎or-cli/src/test‎
java/org/openapi‎tools/codegen/cmd‎
Generate‎Test.java‎ +10 -0
reso‎urces‎
npe-test-sp‎ec-file.yaml‎ +14 -0
npe-te‎st.yaml‎ +8 -0
openapi-generator/s‎rc/…/…/…/…/…/config‎
CodegenConfi‎gurator.java‎ +12 -2
modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java
+ 12
- 2
  • View file @ 32d5c624

  • Edit in single-file editor

  • Open in Web IDE


@@ -534,8 +534,18 @@ public class CodegenConfigurator {
if (validationMessages.size() > 0) {
Set<String> warnings = new HashSet<>();
if (specification != null) {
List<String> unusedModels = ModelUtils.getUnusedSchemas(specification);
unusedModels.forEach(name -> warnings.add("Unused model: " + name));
// Wrap the getUnusedSchemas() in try catch block so it catches the NPE
// when the input spec file is not correct
try{
List<String> unusedModels = ModelUtils.getUnusedSchemas(specification);
if (unusedModels != null) {
unusedModels.forEach(name -> warnings.add("Unused model: " + name));
}
} catch (Exception e){
System.err.println("[error] There is an error with OpenAPI specification parsed from the input spec file: " + inputSpec);
System.err.println("[error] Please make sure the spec file has correct format and all required fields are populated with valid value.");
}
}
if (workflowSettings.isValidateSpec()) {
modules/openapi-generator-cli/src/test/java/org/openapitools/codegen/cmd/GenerateTest.java
+ 10
- 0
  • View file @ 32d5c624

  • Edit in single-file editor

  • Open in Web IDE


@@ -22,7 +22,9 @@ import org.apache.commons.lang3.ArrayUtils;
import org.mockito.MockSettings;
import org.openapitools.codegen.DefaultGenerator;
import org.openapitools.codegen.Generator;
import org.openapitools.codegen.SpecValidationException;
import org.openapitools.codegen.config.CodegenConfigurator;
import org.testng.TestException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -430,4 +432,12 @@ public class GenerateTest {
verify(configurator).toContext();
verifyNoMoreInteractions(configurator);
}
/**
* This test ensures that when the
*/
@Test(expectedExceptions = SpecValidationException.class)
public void testNPEWithInvalidSpecFile() {
setupAndRunTest("-i", "src/test/resources/npe-test.yaml", "-g", "java", "-o", "src/main/java", false, null);
}
}
modules/openapi-generator-cli/src/test/resources/npe-test-spec-file.yaml 0 → 100644
+ 14
- 0
  • View file @ 32d5c624

  • Edit in single-file editor

  • Open in Web IDE

test:
get:
responses:
'200':
description: test
content:
application/json:
schema:
type: object
properties:
prop1:
type: array
prop2:
type: date
\ No newline at end of file
modules/openapi-generator-cli/src/test/resources/npe-test.yaml 0 → 100644
+ 8
- 0
  • View file @ 32d5c624

  • Edit in single-file editor

  • Open in Web IDE

openapi: 3.0.0
info:
description: test
version: test
title: test
paths:
/test:
$ref: 'npe-test-spec-file.yaml#/test'
\ No newline at end of file
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
1
Enhancement: General
1
Enhancement: General
    Assign labels
  • Manage project labels

Milestone
5.3.1
5.3.1 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
3
3 participants
Administrator
William Cheng
Jim Schubert
Reference: OpenAPITools/openapi-generator!10882
Source branch: github/fork/zhuangheihei/#10321-return-parser-exception-instead-of-npe

Menu

Explore Projects Groups Snippets