datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

Doesn't generate models for SpaceTraders OpenAPI

Open kasbah opened this issue 1 year ago • 2 comments

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:

  • OS: Linux
  • Python version: 3.11
  • datamodel-code-generator version: 0.19.0 (also tried master branch @ 2db37451274de3f)

kasbah avatar May 14 '23 10:05 kasbah

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.

kasbah avatar May 14 '23 11:05 kasbah

@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.

koxudaxi avatar Aug 09 '23 16:08 koxudaxi