cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.14k stars 294 forks source link

Variations in CUE's handling of OpenAPI schema #1819

Open verdverm opened 2 years ago

verdverm commented 2 years ago

What version of CUE are you using (cue version)?

0.4.3 / tip

What did you do?

I've been importing the OpenAPI schemas for the OpenAPI spec and noticed some inconsistencies.

# get the specs
exec git clone https://github.com/OAI/OpenAPI-Specification
exec cp OpenAPI-Specification/schemas/v3.0/schema.yaml schema.yaml
exec cp OpenAPI-Specification/schemas/v3.0/schema.json schema.json

# ensure the formats are the same
cue eval schema.yaml schema.json

# yaml versions
exec cue import schema.yaml
exec cue export schema.yaml
exec cat schema.yaml | cue export -

# json version
exec cue import schema.json
exec cue export schema.json
exec cat schema.json | cue export -

What did you expect to see?

more consistency, no errors in the yaml versions

$ cue export schema.yaml 
info.title: incomplete value string:
    ./schema.yaml:53:10
info.version: incomplete value string:
    ./schema.yaml:64:10
openapi: incomplete value =~"^3\\.0\\.\\d(-.+)?$":
    ./schema.yaml:12:6
verdverm commented 2 years ago

Oh, I also think that if I import the OpenAPI v3.0 spec schema, and then use that try to validate other OpenAPI schemas, it will always fail because the openapi field is removed, thus there is always a field which is not allowed.

note to self, find and share reproducer