openapi3-parser icon indicating copy to clipboard operation
openapi3-parser copied to clipboard

[Feature] Support for schemas/strings with JWT format

Open nick75g opened this issue 3 months ago • 3 comments

What is a problem? JWT, or JSON Web Tokens, are a proposed standard for communication via APIs, as per RFC 7519. Currently, if the Parser tries to parse a string with the format JWT, it throws a ParserError: "Invalid vaue for 'format' property, got 'JWT'".

Describe the solution you'd like Support JWT as a String format, and parse OpenAPI specs accordingly.

Describe alternatives you've considered Ignore the JWT format, and format JWT strings as "normal" strings.

nick75g avatar Aug 27 '25 09:08 nick75g

Hey @nick75g, could you provide an example of the spec here to reproduce this behaviour? I am not sure that format should be used for that rather than bearerFormat as mentioned here

manchenkoff avatar Aug 27 '25 09:08 manchenkoff

Good point. I'm not 100% sure either, since I haven't done too much with OpenAPI specs myself, but I'll check in with whoever created the specs I was using. The particular example was formatted like this:

paths:
    /foo:
        post:
            parameters:
                in: header
                name: X-SampleToken
                schema:
                    type: string
                    format: JWT

I noticed that the bearer_auth in that example was empty.

nick75g avatar Aug 28 '25 07:08 nick75g

Good point. I'm not 100% sure either, since I haven't done too much with OpenAPI specs myself, but I'll check in with whoever created the specs I was using.

For this particular case, it should be defined as auth and used in a specific endpoint instead of working with a header parameter manually. However, the string format by default contains only some common values mentioned here - like this.

There is a way to disable this strict enum and use any value by passing strict_enum=False in the parse() method.

manchenkoff avatar Aug 28 '25 09:08 manchenkoff