Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUE does not import "example:" fields from openapi spec #1501

Open
obernil opened this issue Jan 30, 2022 · 2 comments
Open

CUE does not import "example:" fields from openapi spec #1501

obernil opened this issue Jan 30, 2022 · 2 comments
Labels
FeatureRequest New feature or request

Comments

@obernil
Copy link

obernil commented Jan 30, 2022

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

$ cue version
cue version v0.4.1 linux/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

cue import openapi3sample.yaml

(see openapi3sample.yaml for full gist)

-- openapi3sample.yaml --

...
components:
  schemas:
    Pet:
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
          example: 18446744073709551614
        name:
          type: string
        tag:
          type: string
...

What did you expect to see?

-- openapi3sample.cue --

// Swagger Petstore

info: {
	version: *"1.0.0" | string
	title:   *"Swagger Petstore" | string
	license: name: "MIT"
}

#Pet: null | bool | number | string | [...] | {
	//example id: 18446744073709551614
	id:   int
	name: string
	tag?: string
	...
}
#Pets: [...#Pet]
#Error: null | bool | number | string | [...] | {
	code:    int
	message: string
	...
}

What did you see instead?

-- openapi3sample.cue --

// Swagger Petstore

info: {
	version: *"1.0.0" | string
	title:   *"Swagger Petstore" | string
	license: name: "MIT"
}

#Pet: null | bool | number | string | [...] | {
	id:   int
	name: string
	tag?: string
	...
}
#Pets: [...#Pet]
#Error: null | bool | number | string | [...] | {
	code:    int
	message: string
	...
}
@obernil obernil added NeedsInvestigation Triage Requires triage/attention labels Jan 30, 2022
@rogpeppe
Copy link
Member

@obernil Thanks for the report.
To be clear, it seems like this is asking for a new feature: that examples in the OpenAPI schema are imported as comments containing the example. I wonder if the translation should also work the other way around: that specially formatted comments should be exported as examples to OpenAPI. ISTM that this needs some design thought.

@rogpeppe rogpeppe added FeatureRequest New feature or request and removed NeedsInvestigation Triage Requires triage/attention labels Apr 19, 2022
@obernil
Copy link
Author

obernil commented Apr 24, 2022

@rogpeppe thanks

I thought it was something OOTB as the same functionality is present elsewhere (I don't recall exactly where in the docs ATM).

For sure it would make like a good addition as having examples as comments is way more readable than having some nested json/yaml field.

And yes, I'd implement it as a two way thing.

For the CUE comment -> OpenAPI example translation I don't know what a good format would be.

Maybe something lightweight like starting with //-- or even //EX or just unambiguous //example (really just throwing ideas here).

I don't know if there are other constraints language wise though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants