OpenAPITools / OpenAPITools/openapi-generator
[BUG][POSTGRESQL] JSON datatype not recognised for referenced types
Nobody has claimed this yet.
- 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?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
First of all @iri thanks so much for adding a postgres schema generator!
Here's my issue:
When trying to generate a database schema using postgresql-schema, the datatype for referenced ($ref) schemas is not recognised correctly.
openapi-generator version
:latest docker image as of today.
OpenAPI declaration file content or url
"geotag": {
"$ref":"#/components/schemas/geotag"
},
Full file here.
Generation Details
Generating using a Makefile that starts the generator in a docker container.
Steps to reproduce
In the example below I'm showing two properties, geotag and exif both of which should be JSON dataypes. exif is defined in place and correctly assigned the JSON datatype whereas geotag uses a $ref to the schema further down in the screenshot but ends up being classed as TEXT.
Looking at the log, it seems like because the type is detected to be the name of the referenced model it falls back to the default which is TEXT:
Related issues/PRs
Couldn't find any.
Suggest a fix
Digging through the generator code it looked like it required a type property but of course it being a $ref that's not allowed and called out by the validator:
I also tried to use the mysql-schema generator which suffers from the same issue.
The suggested fix would be I guess to check referenced schemas for their datatype instead of only relying on a type property in place.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PostgresqlSchemaCodegen.java around line 367, then reproduce with the referenced geotag and inline exif schemas from the linked api.json. Compare how each property’s datatype is resolved; done means referenced JSON schemas receive the same JSON datatype as equivalent inline schemas.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100