-
Notifications
You must be signed in to change notification settings - Fork 7
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
Demonstrate Microcks Mocking #21
Conversation
1f58daa
to
0e9c6d6
Compare
475e00d
to
777b99e
Compare
eee3c70
to
63166cb
Compare
@paulRbr @scharrier I have updated the microcks pull request as it had a few unrelated changes, so you can clearly see what needs to be done in order for a OpenAPI to work with both Bump.sh and Microcks. Microcks currently requires a) named examples, and b) variables in the response examples in order to reuse request parameters. The names examples show up the same as usual, but they do make the OpenAPI a little more clunky. The variables in the response show up literally in Bump.sh and this of course makes no sense to the user. So, questions:
Probably B, I thought of that mid writing this all out. 😆 Still, thoughts on this would be welcome when you have a moment. |
I tried this after our conversation but relying on single default example raise a lot of other question in the case of multiple response codes, response formats and so on. It works with very basic API (1 input/1 output) but doesn't work with realistic ones.
This is definitely possible to move those "advanced" examples using expressions into another OpenAPI file. |
Hey! Friendly ping @scharrier @paulRbr 🙏
|
100% agree with the overlays proposal: it will allow us to add advanced examples for mocking purpose without havint to complexify the original definition 👍 |
75e6f4e
to
cb423ca
Compare
This will help make sure the OpenAPI is working well within Microcks.
cb423ca
to
4265225
Compare
We recently put together a new Let us know if we can help with anything in order to get this added to https://try.microcks.io |
7e72d8e
to
765262b
Compare
Right! @lbroudoux I have made a |
I'm sorry, but I think my previous comment about overlay was ambiguous. Actually, we don't support an OpenAPI overlay spec that uses patch-like commands. What we do support is importing OpenAPI spec that just contains examples as secondary artifacts. You can see such an example here: https://github.com/microcks/microcks-quickstarters/blob/main/oidc/github.com/github-oidc-1.1.4-openapi-metadata.yaml If you don't want to put all the examples in the original OpenAPI spec, you have the choice between:
Here's the result of using such a file for the Train Travel API: apiVersion: mocks.microcks.io/v1alpha1
kind: APIExamples
metadata:
name: Train Travel API - Microcks
version: '1.0.0'
operations:
'GET /stations':
stations:
request:
response:
status: '200'
mediaType: application/json
body:
data:
- id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
name: Berlin Hauptbahnhof
address: Invalidenstraße 10557 Berlin, Germany
country_code: DE
timezone: Europe/Berlin
- id: b2e783e1-c824-4d63-b37a-d8d698862f1d
name: Paris Gare du Nord
address: 18 Rue de Dunkerque 75010 Paris, France
country_code: FR
timezone: Europe/Paris
links:
self: https://api.example.com/stations&page=2
next: https://api.example.com/stations?page=3
prev: https://api.example.com/stations?page=1
'GET /trips':
trips:
request:
parameters:
date: '2024-02-01T09:00:00Z'
origin: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
destination: b2e783e1-c824-4d63-b37a-d8d698862f1d
response:
status: '200'
mediaType: application/json
body:
data:
- id: ea399ba1-6d95-433f-92d1-83f67b775594
origin: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
destination: b2e783e1-c824-4d63-b37a-d8d698862f1d
departure_time: '2024-02-01T10:00:00Z'
arrival_time: '2024-02-01T16:00:00Z'
price: 50
operator: Deutsche Bahn
bicycles_allowed: true
dogs_allowed: true
- id: 4d67459c-af07-40bb-bb12-178dbb88e09f
origin: b2e783e1-c824-4d63-b37a-d8d698862f1d
destination: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
departure_time: '2024-02-01T12:00:00Z'
arrival_time: '2024-02-01T18:00:00Z'
price: 50
operator: SNCF
bicycles_allowed: true
dogs_allowed: true
links:
self: https://api.example.com/trips?origin=efdbb9d1-02c2-4bc3-afb7-6788d8782b1e&destination=b2e783e1-c824-4d63-b37a-d8d698862f1d&date=2024-02-01
next: https://api.example.com/trips?origin=efdbb9d1-02c2-4bc3-afb7-6788d8782b1e&destination=b2e783e1-c824-4d63-b37a-d8d698862f1d&date=2024-02-01&page=2
'GET /bookings':
bookings:
request:
response:
status: '201'
mediaType: application/json
body:
data:
- id: bfc5af2c-f477-43c4-8bdf-a00bdb939d65
trip_id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
passenger_name: John Doe
has_bicycle: true
has_dog: true
- id: 1725ff48-ab45-4bb5-9d02-88745177dedb
trip_id: b2e783e1-c824-4d63-b37a-d8d698862f1d
passenger_name: Jane Smith
has_bicycle: false
has_dog: false
links:
self: https://api.example.com/bookings
next: https://api.example.com/bookings?page=2
'POST /bookings':
new_booking:
request:
headers:
Content-Type: application/json
body:
trip_id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
passenger_name: John Doe
has_bicycle: true
has_dog: true
response:
status: '201'
mediaType: application/json
body: |-
{
"id": "{{ uuid() > put(bookingId) }}",
"trip_id": "{{ request.body/trip_id }}",
"passenger_name": "{{ request.body/passenger_name }}",
"has_bicycle": {{ request.body/has_bicycle }},
"has_dog": {{ request.body/has_dog }},
"links": {
"self": "https://api.example.com/bookings/{{ bookingId }}"
}
}
'GET /bookings/{bookingId}':
booking_1725ff48-ab45-4bb5-9d02-88745177dedb:
request:
paramaters:
bookingId: 1725ff48-ab45-4bb5-9d02-88745177dedb
response:
status: '200'
mediaType: application/json
body:
id: 1725ff48-ab45-4bb5-9d02-88745177dedb
trip_id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
passenger_name: John Doe
has_bicycle: true
has_dog: true
links:
self: https://api.example.com/bookings/1725ff48-ab45-4bb5-9d02-88745177dedb
booking_bfc5af2c-f477-43c4-8bdf-a00bdb939d65:
request:
paramaters:
bookingId: bfc5af2c-f477-43c4-8bdf-a00bdb939d65
response:
status: '200'
mediaType: application/json
body:
id: bfc5af2c-f477-43c4-8bdf-a00bdb939d65
trip_id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
passenger_name: Billy Bikeless
has_bicycle: false
has_dog: true
links:
self: https://api.example.com/bookings/1725ff48-ab45-4bb5-9d02-88745177dedb What do you think? |
@lbroudoux hey you were clear, this overlay approach is something I thought up with the Bump.sh team. It's not something I expected Microcks to support, it's just a means of getting the original examples out, and the new examples in, and making a new For example, I have updated microcks/community-mocks#25 to use the new URL that I would expect to work once this is merged. |
894c595
to
795048a
Compare
Hey @philsturgeon, @ChristopheDujarric, @scharrier and Bump.sh team! The Train API is now available on https://hub.microcks.io! You can check it out directly here: https://hub.microcks.io/package/bump.sh The Mocks have also been loaded on the https://try.microcks.io instance. You can directly check them there or try a simple call: curl -X GET 'https://try.microcks.io/rest/Train+Travel+API/1.0.0/bookings' -H 'Accept: application/json' Now let's see how we can showcase and promote this during APIdays Paris 😉 Cheers! |
@lbroudoux amazing, thank you so much for getting that done quickly (and on a weekend!) I've just made #36 to help people see the mock server. Have you set this up to "pull" from the URL? Becasue if so, you could chuck that config onto the draft blog post we've been working on, to show how it would work. Then we can just post about making changes to OpenAPI, pushing to Bump, and having it pull to Microcks. |
Hey @philsturgeon, thanks for the follow-up (still on the weekend 😉 ) If you connect on https://try.microcks.io using
|
value: | ||
data: | ||
- id: bfc5af2c-f477-43c4-8bdf-a00bdb939d65 | ||
trip_id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this contain a “real” trip id? e.g. the ea399ba1-6d95-433f-92d1-83f67b775594
one?
has_bicycle: true | ||
has_dog: true | ||
- id: 1725ff48-ab45-4bb5-9d02-88745177dedb | ||
trip_id: b2e783e1-c824-4d63-b37a-d8d698862f1d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, guess it should be a trip id, e.g. 4d67459c-af07-40bb-bb12-178dbb88e09f
?
summary: John Doe | ||
value: | ||
id: 1725ff48-ab45-4bb5-9d02-88745177dedb | ||
trip_id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, let's use a trip id ea399ba1-6d95-433f-92d1-83f67b775594
?
summary: Billy Bikeless | ||
value: | ||
id: bfc5af2c-f477-43c4-8bdf-a00bdb939d65 | ||
trip_id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and last a trip id from the examples data ea399ba1-6d95-433f-92d1-83f67b775594
?
id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e | ||
trip_id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again some two ids should probably be changed with the example booking id and eg trip id?
- target: $.paths["/bookings/{bookingId}/payment"].parameters[?(@.name=="bookingId")] | ||
update: | ||
examples: | ||
Card: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's change the example names for a booking?
This branch aims to get the Train Travel API working with Microcks as smoothly as possible, with good dynamic responses and minimal errors showing up in the Spectral ruleset.