OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] Validation fails when referencing schema properties in other schema

Open
#10,022 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
Description

When referencing properties of a schema inside a schema definition it fails to validate spec but when I skip the validation the correct code is generated

openapi-generator version

5.2.0

OpenAPI declaration file content or url

Concerned specification

Reproduction steps

I am using the npm wrapper to run the following command:
openapi-generator-cli generate -i schema.yaml --additional-properties=typescriptThreePlus=true,modelPropertyNaming=camelCase -g typescript-fetch -o outputDir

And I get this uncaught exception:

Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specificat
ion. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 3, Warning count: 0
Errors:
        -attribute paths.'/parts/{id}/'(patch).requestBody.content.'application/x-www-form-urlencoded'.schema.prop
erties is not of type `object`
        -attribute paths.'/parts/{id}/'(patch).requestBody.content.'multipart/form-data'.schema.properties is not
of type `object`
        -attribute paths.'/parts/{id}/'(patch).requestBody.content.'application/json'.schema.properties is not of
type `object`
        at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:546)
        at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:573)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:433)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Fix

I am currently using the --skip-validate-spec to bypass this error and the correct code is generated so I guess this is a validation error

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 with the linked schema.yaml reproduction and the validation path shown in CodegenConfigurator.toContext and toClientOptInput. Run the supplied openapi-generator-cli command with validation enabled, then confirm that the referenced schema properties are accepted while typescript-fetch generation still produces the correct code.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
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.