How to mock multiple examples with swaggerhub API Mocking tool - OpenAPI 3
Hi all, As per OpenAPI 3 we can have multiple examples. Swaggerhub provides auto-mocking which by default returns the first example (Jessica). I can't find a way to return the second example so in the below I'd like Ron to be returned. Can anyone suggest how to achieve that with Swaggerhub? openapi: 3.0.0 servers: - url: https://localhost/account info: description: This is a simple API version: "1.0.0" title: Simple Inventory API contact: email: you@your-company.com paths: /users: post: summary: Adds a new user requestBody: content: application/json: # Media type schema: # Request body contents $ref: '#/components/schemas/User' # Reference to an object examples: # Child of media type Jessica: # Example 1 value: id: 10 name: Jessica Smith Ron: # Example 2 value: id: 11 name: Ron Stewart responses: 200: description: A user object. content: application/json: schema: $ref: '#/components/schemas/User' # Reference to an object examples: Jessica: value: id: 10 name: Jessica Smith Ron: value: id: 20 name: Ron Stewart components: schemas: User: # Schema name type: object properties: id: type: integer format: int64 Mocked api example in swaggerhub as per above example. POST https://virtserver.swaggerhub.com/myapimock/testExamplesUsers/1.0.0/users In prism/stoplight which implements OpenAPI v 3 you can do this by adding Prefer key to the header. It would be strange for SwaggerHub to no leverage this functionality so I'm assuming I missed something. Many thanks. References: https://swagger.io/docs/specification/adding-examples/ https://app.swaggerhub.com/help/integrations/api-auto-mockingSolved3.1KViews0likes2CommentsCan I host generated stoplight frontend in my own servers?
Originally posted by user mukhamux to the Stoplight Community on 11/29/2022 at 09:40 ET. Hi, I generated beautiful API docs in stoplight service and want host it on my own servers. Are there any ways to do that? Can't find nothing about self-hosted models on the site.Solved92Views0likes1CommentArray Query Parameters Prevent Mocking
Originally posted by user brad.samuels to the Stoplight Community on 10/26/2022 at 19:59 ET. Hi, for some reason whenever I add a query parameter as an array, I cannot successfully submit a mock request. It appears with the error of "Cannot use param value {value}. JSON array expected". In principle, I understand what this means, but the Mock only provides a dropdown (which is already unusual for an array) to select one response. Is there a way I can fix the mock request for: More accurate validation (being a query parameter, it wouldn't make sense to be a JSON array as opposed to ?propertyTypes=house,unit Allow multiple values to be inputted to the field (since it is an array)48Views0likes3CommentsNested Masks don't seem to work
Originally posted by user MarcoDiSarno to the Stoplight Community on 03/07/2024 at 04:40 ET. I have the following use case for masking: Model A is referencing model B. (Garage.cars: array[Car] in the example) Then, a mask on the model A hides some fields and also needs to reference a mask on model B, since that also has some fields to mask. (GaragePublic.cars: array[CarPublic]) Stoplight lets me do that and I thought, "man, nice!" but when publishing the API, all these "nested masks" don't compile. Error: "Invalid JSON pointer: stoplight://resources/overrides/..." Plus, when I export the API with bundled references, it also just shows the "stoplight://resources/overrides/..." refs, which are useless outside of stoplight. The mock server also doesn't work for that project, I suspect for the same reason. Interestingly enough, it seems to work fine in the editor, just outside it doesn't.33Views1like0CommentsPrism takes too long to start up
It takes quite a long time (8-10 minutes) to initialize Prism mock server. All that is logged during this initialization is this message. > [CLI] … awaiting Starting Prism… No log verbosity level setting helps to understand which specific stage of setup takes that long to perform. A swagger.yaml file is quite large, having 380+ type definitions described on 10k+ strings and 290+ paths on 14k+ strings. The mock server from this file is not even starting on cloud Stoplight Workspace I created. The questions are Is it a usual case it takes so long to startup a mock server? Are there any hacks that can help speed up the process? Is there a way to cache the state of the server? Can it be run concurrently? The only approach to speed it up I can think of right now is to split the file on several subdomains (e. g. by paths' first term) and run several prism instances and aggregate them on a single port by using docker compose, as described in the documentation. Have anyone stumbled on a similar issue? Are there better approaches? Thanks!28Views0likes0CommentsIs it possible to limit array lengths in Studio?
Originally posted by user timvanderlinden to the Stoplight Community on 10/28/2022 at 08:32 ET. Hi all! I'm getting my feet wet in mocking with importing OpenAPI docs from our services into Studio. So far so good, but I noticed that the dynamic mocks generates a high amount of elements in array types. I have tried various faker options to limit those amounts, but to no avail. How should I limit the amount of items an array generates? For example: HotspotImage: type: object properties: url: type: string format: uri x-faker: image.imageUrl title: type: string hotspots: type: array items: $ref: '#/components/schemas/Hotspot' x-faker: datatype.array: min: 1 max: 3 required: - hotspots - title - url As you can se above I have attempted to limit the hotspots array to be random between 1 and 3, but without luck, they simply become empty instead of limited. It still generates about 15 items.Solved16Views0likes1CommentPossible to set custom code samples for Request Samples?
Originally posted by user Alexi - Work to the Stoplight Community on 08/29/2023 at 15:28 ET. Hello, I am currently evaluating Stoplight against a few alternatives for OpenAPI documentation. Currently, it looks like all of the examples in the code sample section are set to make HTTP calls in the given language. The product we would be documenting, however, will have it's own SDK, and we'd like any displayed code samples to reflect that usage. Rather than showing how to make an HTTP call in the selected language, we'd like to provide idiomatic examples that leverage our SDK instead. Is it currently possible to do so in Stoplight? I didn't see anything in the docs, but may have missed it. If not, is it possible to disable the code samples altogether? We may prefer not to show anything if we can't customize them.Solved12Views0likes2CommentsHow I can create a Libre for errors in Stoplight
Originally posted by user Inocêncio Cordeiro to the Stoplight Community on 11/22/2023 at 04:20 ET. Its possible create a libre for error, because every time I am design a new API a need import the errors. I don't want create the error everytime. We can have a repo, libre or other thing to save and use errors every time I need.Solved3Views0likes1Comment