openapi-generators / openapi-python-client

Generate modern Python clients from OpenAPI
MIT License
1.25k stars 193 forks source link

Won't generate client for JSON formatted API with tabs #924

Open derenrich opened 8 months ago

derenrich commented 8 months ago

Describe the bug

Running

openapi-python-client generate --url https://raw.githubusercontent.com/wikimedia/mediawiki-extensions-Wikibase/e45d4f725e25a95ec2b034238fd3736f19053a16/repo/rest-api/specs/openapi.json

gives me the error

Error(s) encountered while generating, client was not created

Invalid YAML from provided source: while scanning for the next token
found character '\t' that cannot start any token
  in "<byte string>", line 2, column 1:
        "openapi": "3.1.0",
    ^

This is a follow-on to this old bug https://github.com/openapi-generators/openapi-python-client/issues/488 which got fixed in https://github.com/openapi-generators/openapi-python-client/commit/b01db03349eb83e4c3ffdd1cc70f7eb2a9c6dae8 . It appears the fix doesn't quite work because github doesn't serve JSON files with the expected content-type (curl with -v gives me "< content-type: text/plain; charset=utf-8").

OpenAPI Spec File I was trying to generate a client for this code

Desktop (please complete the following information):

Additional context I think the correct fix ought to be to fall back to JSON parsing in the event of YAML parsing failure (or else a flag to specify?). I'm not sure why the mimetype isn't being guessed right

derenrich commented 8 months ago

I got it to work by downloading a local copy and then running a bundler to condense it into a single file (unsure if support for that is intended). It runs but produces this warning and does nothing useful

Warning(s) encountered while generating. Client was generated, but some pieces may be missing

WARNING parsing GET /entities/items/{item_id} within items. Endpoint will not be generated.

Union[Unset, List[str]] is not allowed in header

Parameter(name='If-None-Match', param_in=<ParameterLocation.HEADER: 'header'>, description=None, required=False, deprecated=False, allowEmptyValue=False, style=None, explode=False, allowReserved=False, param_schema=Schema(title=None, multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern=None, maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=<DataType.ARRAY: 'array'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=Schema(title=None, multipleOf=None, maximum=None, exclusiveMaximum=None, minimum=None, exclusiveMinimum=None, maxLength=None, minLength=None, pattern='^(?:".+"|\\*)$', maxItems=None, minItems=None, uniqueItems=None, maxProperties=None, minProperties=None, required=None, enum=None, const=None, type=<DataType.STRING: 'string'>, allOf=[], oneOf=[], anyOf=[], schema_not=None, items=None, properties=None, additionalProperties=None, description=None, schema_format=None, default=None, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None), properties=None, additionalProperties=None, description=None, schema_format=None, default=None, nullable=False, discriminator=None, readOnly=None, writeOnly=None, xml=None, externalDocs=None, example=None, deprecated=None), example=None, examples=None, content=None)

for every endpoint so it seems to be mad still. I'll poke around and maybe file another ticket.

derenrich commented 8 months ago

I was able to work around the issue and got the generated library working. Thanks for this tool!

derenrich commented 8 months ago

Actually looking further it seems that the generated code is always setting the parsed response to None. very strange