hackworthltd / primer-app

Primer's React frontend application.
GNU Affero General Public License v3.0
3 stars 0 forks source link

Errors about openapi spec printed when entering dev shell or running `pnpm generate` #618

Open brprice opened 1 year ago

brprice commented 1 year ago

When entering a nix develop shell (or manually using pnpm generate), there are lots of messages printed of the form

Message : Property names must be snake case
Path    : paths,/openapi/sessions/{sessionId}/program,get,responses,200,content,application/json;charset=utf-8,schema,properties,modules,items,properties,types,items,properties,qualifiedModule

It appears that many of these are printed twice, once as a warning and once as an error. All the warnings are in one batch, followed by all the errors.

Note that there are a few different sorts of errors, and many messages are printed. As a simple summary I ran nix28 develop -c 'true' > /tmp/msgs 2>&1 and found 503 lines (though a few are from nix, and not all are warnings etc). The unique messages (ignoring the Path lines) are

Message : A 201 or 202 status code should be returned by a 'create' operation.
Message : All request bodies MUST be structured as an object
Message : API definition should not contain circular references.
Message : Array schemas should define a numeric maxItems field
Message : Array schemas should define a numeric minItems field
Message : Common path parameters should be defined on the path object.
Message : Enum values must be snake case
Message : Major version segment not present in either server URLs or paths
Message : OpenAPI object must have non-empty "tags" array.
Message : OpenAPI "servers" must be present and non-empty array.
Message : Operation "description" must be present and non-empty string.
Message : Operation ids must be snake case
Message : operationIds should follow naming convention: operationId verb should be list
Message : Operation must have non-empty "tags" array.
Message : Operations should not return an array as the top-level structure of a response.
Message : Parameter should have a non-empty description
Message : Path parameter names must be snake case
Message : Path segments must be snake case: copy-session
Message : Property names must be snake case
Message : Query parameter names must be snake case
Message : Request bodies and non-204 responses should define a content object
Message : Schema property should have a non-empty description
Message : Schema should have a non-empty description
Message : Should define a maxLength for a valid string
Message : Should define a minLength for a valid string
Message : Should define a pattern for a valid string

And the worrying lines not of this form are

🍻 Start orval v6.10.2 - A swagger client generator for typescript
'lodash/isPlainObject' is imported by ^@lodash/isPlainObject?commonjs-external, but could not be resolved – treating it as an external dependency
'lodash/isEqual' is imported by ^@lodash/isEqual?commonjs-external, but could not be resolved – treating it as an external dependency
'lodash/uniqWith' is imported by ^@lodash/uniqWith?commonjs-external, but could not be resolved – treating it as an external dependency
'lodash/pickBy' is imported by ^@lodash/pickBy?commonjs-external, but could not be resolved – treating it as an external dependency

and

▲ [WARNING] "import.meta" is not available in the configured target environment ("es2015") and will be empty [empty-import-meta]

    src/primer-api/mutator/use-custom-instance.ts:4:11:
      4 │   baseURL: import.meta.env["VITE_API_URL"],

It is not clear how many of these indicate actual problems (e.g. in our openapi spec). Nor is it clear how many root causes there are. As we understand more it may be sensible to split this issue up. For now, I will use this issue to record my current understanding.

dhess commented 1 year ago

I think there's nothing we can do about the lodash warnings, as those are coming from a dependency.

Regarding the import.meta warning: I think this warning is simply invalid. baseURL is being set correctly both in development (locally) and in production. I've been aware of this one for awhile and I still don't understand why it's complaining.

brprice commented 1 year ago

I understand where the first (in the OP's ordering) batch of messages come from, and have some idea of how "important" they are. These ones are of the form

Message : ...
Path    : ...

Orval seems to call ibm-openapi-validator, which is (surprise!) a validator for openapi specs, written by IBM. By default this validator is stricter than the official spec (it checks against their in-house conventions). In particular, I believe all the snake case errors are not errors per the spec, but only differ from IBM's conventions.

For some more info, see https://github.com/IBM/openapi-validator/issues/173 https://github.com/IBM/openapi-validator/pull/41 https://github.com/IBM/openapi-validator/blob/main/docs/ibm-cloud-rules.md#customization

Note that orval uses ibm-openapi-validator ^0.88.0 (in particular, we currently lock it at 0.88.3: https://github.com/hackworthltd/primer-app/blob/3bb7547f315c402d8a9b13df57ef570fd18f23e4/pnpm-lock.yaml#L14164.

brprice commented 1 year ago

One useful trick is to add "ibm-openapi-validator" : "^0.88.0" to devDependencies in package.json and directly run the underlying linter in verbose mode lint-openapi -v primer-api.json which will then say what rule is being fired.

These rules are defined in https://github.com/IBM/openapi-validator/tree/main/packages/ruleset

dhess commented 1 year ago

pnpm has support for overriding dependencies, as well, so we could also pin it to the latest version that I think you had earlier said might handle these better, or something?

brprice commented 1 year ago

pnpm has support for overriding dependencies, as well, so we could also pin it to the latest version that I think you had earlier said might handle these better, or something?

I think I was confused when I said that. I don't currently think a newer version would make any difference here.

brprice commented 1 year ago

619 will tell orval to not worry about case conventions, dealing with one class of messages. The rest are (along with occurrence counts):

As far as I know, none of these are problems according to the openapi spec, but only for ibm's sense of taste.

brprice commented 1 year ago

There are a few general categories that make up most the warnings here:

I suggest we deal with these and then have another think about the miscellaneous other ones.

dhess commented 1 year ago

Many of those sound warnings sound like reasonable changes to make. I suppose we can think of these as linting. But it's not a high priority, in any case.