openapi-python-client icon indicating copy to clipboard operation
openapi-python-client copied to clipboard

Won't generate client for JSON formatted API with tabs

Open derenrich opened this issue 2 years ago • 3 comments

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):

  • OS: Ubuntu 20.04.6 LTS running under Windows 11
  • Python Version: 3.8.0
  • openapi-python-client version 0.17.0

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 avatar Jan 02 '24 04:01 derenrich

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 avatar Jan 02 '24 04:01 derenrich

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

derenrich avatar Jan 02 '24 21:01 derenrich

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

derenrich avatar Jan 03 '24 06:01 derenrich