Skip to content
New issue

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

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

Already on GitHub? # to your account

[rust-server] lacks support for additionalProperties #318

Open
bjgill opened this issue Jun 14, 2018 · 3 comments · Fixed by #3666
Open

[rust-server] lacks support for additionalProperties #318

bjgill opened this issue Jun 14, 2018 · 3 comments · Fixed by #3666

Comments

@bjgill
Copy link
Contributor

bjgill commented Jun 14, 2018

Description

See swagger-api/swagger-codegen#8089 (comment) - our main bar to using the same swagger spec for sample generation as the other generators is that rust-server does not yet support additionalProperties.

Admittedly, this seems like a non-trivial problem. rust-server is intended to provide a distributed strongly-typed system. As soon as you add additionalProperties, however, we lose the ability to be able to verify the contents of said additional properties.

A naive solution might be:

struct Foo {
    bar: Option<i32>,
    additionalProperties: HashMap<String, json::Object>,
};

However, this will fail as soon as we introduce non-json media types (e.g. XML, which rust-server supports). As such, I'm not sure what a complete solution would look like...

openapi-generator version
OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
@bjgill
Copy link
Contributor Author

bjgill commented Jul 26, 2018

This may be at least partially a regression. The following spec worked in swagger-codegen:

swagger: '2.0'
info:
  description: "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\"
  version: 1.0.0
  title: OpenAPI Petstore
  license:
    name: Apache-2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: petstore.swagger.io:80
basePath: /v2
schemes:
  - http
paths:
  /pet:
    post:
      summary: Add a new pet to the store
      description: ''
      operationId: addPet
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: body
          name: body
          description: Pet object that needs to be added to the store
          required: true
          schema:
            $ref: '#/definitions/additionalPropertiesObject'
      responses:
        '405':
          description: Invalid input
definitions:
  additionalPropertiesObject:
    description: An additionalPropertiesObject
    type: object
    additionalProperties:
      type: string
    example: "foo"

@bjgill
Copy link
Contributor Author

bjgill commented Jul 27, 2018

OK - what's happened is that we never supported additional properties. openapi-generator introduced a regression that caused a compile failure. I've put in a workaround in #671 to restore things to how they previously were - i.e. that the additionalProperties directive is simply ignored.

@richardwhiuk
Copy link
Contributor

We still don't entirely support additional properties - e.g. we don't support objects which mix additional properties and non-additional properties.

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

Successfully merging a pull request may close this issue.

2 participants