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

How to generate example in OpenAPI3 #2939

Closed
ouvreboite opened this issue Feb 20, 2024 · 14 comments
Closed

How to generate example in OpenAPI3 #2939

ouvreboite opened this issue Feb 20, 2024 · 14 comments
Assignees

Comments

@ouvreboite
Copy link

I see that generating per-field example in OpenAPIv3 is not supported (cf typespec-for-openapi).

Is there a specific reason for that, or are you open for a PR to add this support?

@timotheeguerin
Copy link
Member

Hi, we have an implementation issue that hasn't been implemented yet #2700

However it is a little bigger than just openapi3 examples. We are definitely open to PR and if you are intrested in implementing on the decorator and openapi3 part (without the versioning) I think that would be fair to split.

@ouvreboite
Copy link
Author

That's nice to hear :)

The linked PR (#2700) seems broader, as it tries to tackle both "object" examples and "per property" examples. I would rather focus on "per property" example first, as it would have no impact on versioning and be simpler to implement.

Something like that:

model Person
{   
    @example("Alice")
    name: string;

    @example(42) 
    @added(Versions.v2) 
    age: int32;
}

@markcowl
Copy link
Contributor

@ouvreboite That is covered by #2700, although the 'simple' example is a bit buried in the details:

model Foo {
  type: "bar" | "baz"
  @jsonExample("2023-03-01T19:00:00Z")
  createdAt: utcDateTime;
}

Which for your example would be:

model Person
{   
    @jsonExample("Alice")
    name: string;

    @jsonExample(42) 
    @added(Versions.v2) 
    age: int32;
}

@markcowl
Copy link
Contributor

Note that, even property examples potentially have versioning implications, as example values can become obsolete over time

@markcowl
Copy link
Contributor

@ouvreboite Please let us know if this implementation will enable what you need, or if you have questions or concerns.

@markcowl markcowl self-assigned this Feb 22, 2024
@ouvreboite
Copy link
Author

@markcowl LGTM :)

@tobiashochguertel
Copy link

When can I use this or test it?

@tobiashochguertel

This comment was marked as off-topic.

@markcowl
Copy link
Contributor

We are adding some new capabilities to OpenAPI for representing value types: #2046

We are integrating this into the Sample design and should have an updated design this month, with implementation to follow next month.

@KieranP
Copy link

KieranP commented Jun 11, 2024

@markcowl Has there been any progress on this? I have been porting a large OpenAPI file to Typespec today, and almost everything we need is supported except Examples for properties, which has meant we need to put the conversion on hold until it is supported.

@timotheeguerin
Copy link
Member

we have agreed on the first version of the updated design and should be working on it soon, planning for this incoming sprint(releasing next month as we are just about to release today)

@dmunch
Copy link

dmunch commented Jun 11, 2024

great news! The first version of the updated design, is it the one you've outlined here ? Very keen to get my hands on this - Just been starting to use TypeSpec for a new service and found it great so far, but really am missing the possibility to add examples for OpenAPI.

@timotheeguerin
Copy link
Member

Yea that one except all the scoping was cut for now, just a single arg with the example

@timotheeguerin
Copy link
Member

timotheeguerin commented Jun 13, 2024

Will actually close this issue in favor of the other one #2700, I have started working on it,
Playground demo

PR #3572 if you have feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants