OpenAPI-specific Formats not supported
See original GitHub issueI’m submitting a…
- bug report
- feature request
What is the current behavior?
Setting the format
for an integer doesn’t work.
test.yaml:
openapi: "3.0.2"
info:
title: "Test"
description: "Test spec"
version: "1.0.0"
contact:
name: "Rob"
tags:
- name: tag1
servers:
- url: http://example.com
paths:
/:
get:
operationId: root
tags:
- tag1
summary: root
description: The root node
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
ip_address:
description: IP address (as a `long int`)
type: integer
format: int64
example: 2886989840
responses:
'200':
description: Nothing returned
Run:
$ spectral lint test.yaml
Linting test.yaml
OpenAPI 3.x detected
Encountered error when running rule 'valid-example' on node at path '$,paths,/,get,requestBody,content,application/x-www-form-urlencoded,schema,properties,ip_address':
Error: unknown format "int64" is used in schema at path "#"
No errors or warnings found!
What is the expected behavior?
Spectral should not display:
Error: unknown format "int64" is used in schema at path "#"
Also, it should not display No errors or warnings found! when the line above starts with the word Error
!
What is the motivation / use case for changing the behavior?
The Spec says that int64
is a valid format
and the petstore-expanded example shows it in use.
Please tell us about your environment:
$ spectral --version
@stoplight/spectral/2.1.1 darwin-x64 node-v8.12.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
OpenAPI Specification - Version 3.0.3 - Swagger
An OpenAPI document compatible with OAS 3.*. ... Tools that do not recognize a specific format MAY default back to the type alone,...
Read more >API import restrictions and known issues - Azure
Details of known issues and restrictions on OpenAPI, WSDL, and WADL formats support in Azure API Management.
Read more >OpenAPI Specification v3.0.3 | Introduction, Definitions, & More
OAS uses several known formats to define in fine detail the data type being used. However, to support documentation needs, the format property ......
Read more >OpenAPI Compatibility Chart - ReadMe Documentation
We currently support OpenAPI through v3.1.0. ... We support both global and operation-specific security requirements. ✓ ... We currently do not support
Read more >OpenAPI 3.0 Tutorial | SwaggerHub Documentation
OpenAPI 3.0 is an open-source format for describing and documenting ... and non unique, so they can be specified multiple times in the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Alright edging closer to a complete solution, you no longer need
--skip-rule
you can just upgrade to v2.3.1 and the errors will stop being thrown.@akrabat ok I dug into this and figured it out.
OpenAPI declares int64 is valid in the text doc, but formats are not defined in the OpenAPI metaschema so shoving that metaschema into a JSON Schema validator doesn’t make it 100% into an OpenAPI validator as expected.
We are then getting an error because AJV v6 (which we use) is defaulting to throwing exceptions for unknown formats:
Somebody out there has noticed this before and created BiteBit/ajv-oai which is a wrapper for AJV which also declares the OpenAPI formats, and tells AJV about them.
We will need to either switch to using this package, or take a similar approach to adding these formats when we know OAS2/3 is being used.
A short term solution will be switch to using “ignore”, which means we are not catching mismatches in formats unknown to AJV, which will at least stop this error from happening, and stop people needing to
--skip-rule=valid-example
just go get spectral working,.Somebody will update this issue when one of those two things happens.