OpenAPITools / OpenAPITools/openapi-generator

[REQ] Fail build on illegal schema if schema should be validated

Open
#18,221 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

Hi,
I've recently discovered that the OpenAPI generator (we use the maven plugin, but shouldn't matter as far as what I've seen in the code) doesn't fail if an illegal schema is found. In our particular case, it was $ref with other properties. This check is made and logged in the InlineModelResolver Line 269-279. I expected that this kind of error causes a build failure but it doesn't because it simply logs a warning and returns.

Describe the solution you'd like

The build should fail if validateSpec is true. This can be achieved by throwing an exception after logging the error. This would require to pass this flag to the method as parameter. This seems to be quite difficult. The more feasible approach seems to add a new field that stores if the schema should be validated and use the field value in the method. Then one could set this value when instantiating a new InlineModelResolver (DefaultGenerator Line 283).

Describe alternatives you've considered

I don't know if my proposed change is a good solution from an architectural point of view. I'm open to other suggestions and willing to implement the required changes.

Additional context

Is there a specific reason why these kind of errors do not cause the generator to fail?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in InlineModelResolver around lines 269-279 to trace how illegal schemas are logged, then inspect DefaultGenerator around line 283 and the validateSpec setting. Determine how validation state reaches the resolver and verify that an illegal schema causes generation to fail when validateSpec is true without changing behavior otherwise.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.