# Open-generator-cli problems, or Swagger/OpenApi recommendations

**URL:** <https://discourse.elm-lang.org/t/open-generator-cli-problems-or-swagger-openapi-recommendations/4644>\
**Category:** Request Feedback\
**Created:** [November 9, 2019, 11:20am UTC](https://discourse.elm-lang.org/t/open-generator-cli-problems-or-swagger-openapi-recommendations/4644 "2019-11-09T11:20:23Z")\
**Posts on this page:** 7\
**Page:** 4

<div class="post-metadata">

**Author:** ![mattiasw](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mattiasw/32/908_2.png) [@mattiasw](https://discourse.elm-lang.org/u/mattiasw)\
**Post date:** [January 12, 2020, 9:16pm UTC](https://discourse.elm-lang.org/t/open-generator-cli-problems-or-swagger-openapi-recommendations/4644/61 "2020-01-12T21:16:22Z")

</div>

@eriktimmers Nice!!!

---

<div class="post-metadata">

**Author:** ![eriktimmers](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/eriktimmers/32/1114_2.png) [@eriktimmers](https://discourse.elm-lang.org/u/eriktimmers)\
**Post date:** [January 20, 2020, 11:25am UTC](https://discourse.elm-lang.org/t/open-generator-cli-problems-or-swagger-openapi-recommendations/4644/62 "2020-01-20T11:25:28Z")

</div>

@mattiasw how is it working for you now?

I found quite a major bug when dealing with requests that return nothing. I fixed it in [this PR](https://github.com/OpenAPITools/openapi-generator/pull/5055/files).

Also wanted to let you know the new Elm generator is now part of the [SNAPSHOT releases](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/5.0.0-SNAPSHOT/).

---

<div class="post-metadata">

**Author:** ![mattiasw](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mattiasw/32/908_2.png) [@mattiasw](https://discourse.elm-lang.org/u/mattiasw)\
**Post date:** [January 20, 2020, 12:42pm UTC](https://discourse.elm-lang.org/t/open-generator-cli-problems-or-swagger-openapi-recommendations/4644/63 "2020-01-20T12:42:07Z")

</div>

Everything is working fine. All my calls return a value, so didn’t notice the bug. Regenerated and diffed, and no changes on the generated code except you new header.

---

<div class="post-metadata">

**Author:** ![eriktimmers](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/eriktimmers/32/1114_2.png) [@eriktimmers](https://discourse.elm-lang.org/u/eriktimmers)\
**Post date:** [January 20, 2020, 1:00pm UTC](https://discourse.elm-lang.org/t/open-generator-cli-problems-or-swagger-openapi-recommendations/4644/64 "2020-01-20T13:00:08Z")

</div>

Thanks, that’s good to hear!

---

<div class="post-metadata">

**Author:** ![lazurski](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/lazurski/32/2785_2.png) [@lazurski](https://discourse.elm-lang.org/u/lazurski)\
**Post date:** [January 21, 2020, 9:36am UTC](https://discourse.elm-lang.org/t/open-generator-cli-problems-or-swagger-openapi-recommendations/4644/65 "2020-01-21T09:36:56Z")

</div>

We are thinking about the following. The app is deployed quite often and sometimes the API definition and generated API changes. Some users have the client open in a tab for long time and sometimes the session overlaps the deployment. In such case our users are getting errors.

I’d like to get any thoughts about this. Below are my early thoughts about it.

What we are considering now is to store a hash of the `openapi.yaml` file in app’s model (maybe baked in JS code and passed through flags). The same hash should be attached to every API response (I think headers are appropriate for this). If the hash in the response doesn’t match the one in the model, we would pass an error to the `Msg` constructor and update would reload the page.

- Do you (community) think it’s a good approach?

- Should versioning of the API be somehow supported by Elm OpenAPI Generator?

---

<div class="post-metadata">

**Author:** ![eriktimmers](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/eriktimmers/32/1114_2.png) [@eriktimmers](https://discourse.elm-lang.org/u/eriktimmers)\
**Post date:** [January 21, 2020, 10:38am UTC](https://discourse.elm-lang.org/t/open-generator-cli-problems-or-swagger-openapi-recommendations/4644/66 "2020-01-21T10:38:43Z")

</div>

@lazurski what you could typically do is have a versioned base path, like `https://example.com/api/1.0.0/`. All your endpoints are prefixed with that value. See also the [OpenAPI docs](https://swagger.io/docs/specification/api-host-and-base-path/).

Instead of hashing the yaml, OpenAPI already supports versioning the specification. (Although with hashing you have the guarentee it gets updated).

Your spec could look like this:

```auto
openapi: '3.0'

info:
  version: 1.0.0
  title: ExampleApi
  description: Example API

servers:
  - url: https://example.com/api/1.0.0

...

```

Or, like you suggested, you could add a header to each request with the right version. Back-end wise it might be easier to deploy different versions under different paths though.

The OpenAPI Elm Generator could also expose the `info.version` value which would allow you to add a path parameter to each path. Whether you prefer this or updating the base path directly is up to you. Both could be stored in the model.

> **Example of using a path parameter**
>
> ```auto
> openapi: '3.0'
> 
> info:
> version: 1.0.0
> title: ExampleApi
> description: Example API
> 
> servers:
> - url: https://example.com/api
> 
> paths:
> /{apiVersion}/persons:
> get:
> summary: Get all persons
> parameters:
> - $ref: '#/components/parameters/ApiVersion'
> ...
> 
> components:
> parameters:
> ApiVersion:
> name: apiVersion
> in: path
> description: API version
> required: true
> schema:
> type: string
> format: uuid
> 
> ```

So I think OpenAPI already has several options on how to handle this. But it mostly is also depending on how you’d like to deploy the different back-ends. If some small tweaks like exposing the `info.version` is needed we can update the generator. However, I do not think an out of the box versioning needs to be part of that generator.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [January 31, 2020, 10:38am UTC](https://discourse.elm-lang.org/t/open-generator-cli-problems-or-swagger-openapi-recommendations/4644/67 "2020-01-31T10:38:50Z")

</div>

Closed on January 31, 2020, 10:38am UTC

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.elm-lang.org/t/open-generator-cli-problems-or-swagger-openapi-recommendations/4644.md?page=3)
