koxudaxi / datamodel-code-generator

Pydantic model and dataclasses.dataclass generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.
https://koxudaxi.github.io/datamodel-code-generator/
MIT License
2.6k stars 290 forks source link

Doesn't generate models for SpaceTraders OpenAPI #1319

Open kasbah opened 1 year ago

kasbah commented 1 year ago

Describe the bug Doesn't generate models for SpaceTraders OpenAPI spec.

To Reproduce

$ datamodel-codegen --url https://raw.githubusercontent.com/SpaceTradersAPI/api-docs/main/reference/SpaceTraders.json --output models.py
The input file type was determined to be: openapi
This can be specificied explicitly with the `--input-file-type` option.
Models not found in the input data

or

$ git clone https://github.com/SpaceTradersAPI/api-docs
$ datamodel-codegen --input api-docs/reference/SpaceTraders.json --output=models.py
The input file type was determined to be: openapi
This can be specificied explicitly with the `--input-file-type` option.
Models not found in the input data

Expected behavior Generates models ;)

Version:

kasbah commented 1 year ago

I found that adding --openapi-scopes=paths gives me pydantic models. I'm not quite sure what that setting does actually. Would be really nice to get some hints from datamodel-codegen that the paths or whatever it is might be the issue.

koxudaxi commented 1 year ago

@kasbah I'm sorry for my late response. The code generator generates models from components.schemas in OpenAPI as default. But, the OpenAPI Spec has an empty schemas object.

  "components": {
    "requestBodies": {},
    "schemas": {},

In this case, you should add specific scopes like --openapi-scopes=paths which has models spec.