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

[BUG] No setter function generated for arrays #3769

Closed
1 task
julesdent opened this issue Aug 27, 2019 · 12 comments · Fixed by #3837
Closed
1 task

[BUG] No setter function generated for arrays #3769

julesdent opened this issue Aug 27, 2019 · 12 comments · Fixed by #3837

Comments

@julesdent
Copy link

Bug Report Checklist

  • [ x] Have you provided a full/minimal spec to reproduce the issue?
  • [ x] Have you validated the input using an OpenAPI validator (example)?
  • [ x] What's the version of OpenAPI Generator used?
  • [ x] Have you search for related issues/PRs?
  • [ x] What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

No setter function is generated for an array.

openapi-generator version

4.1.1

OpenAPI declaration file content or url
openapi: 3.0.0
servers:
  - description: SwaggerHub API Auto Mocking
    url: 'https://virtserver.swaggerhub.com/'
info:
  description: API
  version: 1.0.1
  title: API
  termsOfService: 'http://swagger.io/terms/'
tags:
  - name: FuelCosts
paths:
  '/FuelCosts':
    get:
      description: Obtain fuel costs
      tags:
        - FuelCosts
      summary: Get fuel cost
      operationId: GetFuelCostQuery
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FuelCost'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    FuelCost:
      type: object
      properties:
        Remarks:
          type: array
          items:
            type: string
Command line used for generation

java -jar openapi-generator-cli-4.1.1.jar generate -i ./Bug.json -g cpp-pistache-server -o generated

Steps to reproduce

Generate the C++ code from the spec. In the generated FuelCost.h, there is a getter function for Remarks but no setter:
///


///
///

std::vectorstd::string& getRemarks();
bool remarksIsSet() const;
void unsetRemarks();

Related issues/PRs

#3271

Suggest a fix

As a workaround, you can derive a class from FuelCost and add a setter function manually, but this should really be handled by the generator.

@auto-labeler
Copy link

auto-labeler bot commented Aug 27, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@wing328
Copy link
Member

wing328 commented Aug 27, 2019

there is a getter function for Remarks but no setter:

What does the correct code for setter look like? That can help us to update the mustache template more easily.

@julesdent
Copy link
Author

I would expect the setter to look something like this:

void FuelCost::setRemarks(const std::vector<std::string>& value)
{
    m_Remarks = value;
    m_RemarksIsSet = true;
}

@julesdent
Copy link
Author

A setter like the following would also be useful to allow setting from any container type:

    template <typename IteratorType>
    void setRemarks(IteratorType Begin, IteratorType End)
    {
        m_Remarks.assign(Begin, End);
        m_RemarksIsSet = true;
    }

@etherealjoy
Copy link
Contributor

etherealjoy commented Sep 5, 2019

@julesdent
Actually there is no setter for the array because the array could be get and items inserted directly.

But this is a common request, so we will look into this as it is not a breaking change.

@etherealjoy
Copy link
Contributor

@muttleyxd
Copy link
Contributor

@etherealjoy I was working on this, but got sidetracked in the end (and my approach had too much code-breaking changes)
#3417

Should we tackle this just by adding the required setters?
Also .get() is broken since it doesn't set 'isSet' variable IIRC

@etherealjoy
Copy link
Contributor

etherealjoy commented Sep 5, 2019

@etherealjoy I was working on this, but got sidetracked in the end (and my approach had too much code-breaking changes)
#3417

Yes I checked the other issue again today, and I agree generally about refactoring but code breaking is bad experience for end users, unless we have a major version going forward.
Then I leave this with you to continue.

Should we tackle this just by adding the required setters?

Yes, I think we could add, there are too many users expecting it.

Also .get() is broken since it doesn't set 'isSet' variable IIRC

Indeed, one way we can check is during serialization if there are items in the map, vector, (like how qt5 client is doing), either one is fine, (but if we expose get and set and user can set the array with a get )

@muttleyxd
Copy link
Contributor

Yes I checked the other issue again today, and I agree generally about refactoring but code breaking is bad experience for end users, unless we have a major version going forward.
Then I leave this with you to continue.

I guess we could think about switching to my approach for 5.0 release? This would yield much smaller amount of code. Also we could use Pistache::Optional for optionals, so everything could be a structure and have optional fields implemented in simple way.

Yes, I think we could add, there are too many users expecting it.
Okay, let's do it for 4.*

Indeed, one way we can check is during serialization if there are items in the map, vector, (like how qt5 client is doing), either one is fine, (but if we expose get and set and user can set the array with a get )
To clarify, what should we do here:

  • add 'set', which would set isSet
  • make 'get' set isSet
  • auto-detect if vector is set, problem is that someone may want to send and empty array

I'd go with make 'get' set isSet, if someone will want an empty array, they could call get(), if someone doesn't want it, they could use unset

@etherealjoy
Copy link
Contributor

etherealjoy commented Sep 5, 2019

add 'set', which would set isSet
make 'get' set isSet
auto-detect if vector is set, problem is that someone may want to send and empty array
I'd go with make 'get' set isSet, if someone will want an empty array, they could call get(), if someone doesn't want it, they could use unset

Just a small proposal to your thought process here
What about set setting the isSet value.
If the array is empty and the isSet is set then we send anyway. Covers use case of user wanting to send empty array

If the array is not empty we send anyway, covers all exisiting cases. User could have accessed it with the get, or might have explicitly set with the set method.

@etherealjoy
Copy link
Contributor

I guess we could think about switching to my approach for 5.0 release? This would yield much smaller amount of code. Also we could use Pistache::Optional for optionals, so everything could be a structure and have optional fields implemented in simple way.

Lets also ask @wing328 for his opinion on this.

muttleyxd added a commit to muttleyxd/openapi-generator that referenced this issue Sep 5, 2019
@muttleyxd
Copy link
Contributor

Just a small proposal to your thought process here
What about set setting the isSet value.
If the array is empty and the isSet is set then we send anyway. Covers use case of user wanting to send empty array

If the array is not empty we send anyway, covers all exisiting cases. User could have accessed it with the get, or might have explicitly set with the set method.

Take a look at #3837

etherealjoy pushed a commit that referenced this issue Sep 7, 2019
* [C++][Pistache] Add missing setter for arrays

Fixes #3769

* [C++][Pistache] Update Petstore sample
@etherealjoy etherealjoy added this to the 4.1.2 milestone Sep 7, 2019
hokamoto pushed a commit to hokamoto/openapi-generator that referenced this issue Sep 12, 2019
* [C++][Pistache] Add missing setter for arrays

Fixes OpenAPITools#3769

* [C++][Pistache] Update Petstore sample
wing328 pushed a commit that referenced this issue Sep 13, 2019
* First version of Nim Client

* Add some codes

* Add some codes

* Add some codes

* Add some codes

* Add some codes

* First version of Nim Client

* Add some codes

* Add some codes

* [Dart] Fix README template and update testing doco (#3809)

* [Dart] Fix README template and update testing doco

- deleted redundant shell script
- fixed and updated README template
- updated test package and moved to a dev_dependency
- removed old unused dev_dependency packages
- updated testing documentation in petstore sample

* Remove references to dart-flutter-petstore.sh

* Fix typos

* Fix typo

* Support custom git repository (#3757)

* add gitHost param to GeneratorSettings and related

* parameterize gitHost in READMEs

* parameterize gitHost in go.mod

* parameterize gitHost in git_push

* update petstore samples

* run ./bin/utils/export_docs_generators.sh

* run meta-codehen.sh

* Revert "run meta-codehen.sh"

This reverts commit d6d579f.

* Revert "run ./bin/utils/export_docs_generators.sh"

This reverts commit 1b81538.

* Revert "update petstore samples"

This reverts commit f513add.

* run ensure-up-to-date

* Add links to article and video (#3820)

* Better Go code format (#3819)

* better varible naming

* better comments

* better code format for go experimental client

* better comment, update samples

* Add some codes

* Add some codes

* Add some codes

* Add gRPC Protobuf schema generator (#3818)

* add grpc protobuf generator

* update doc

* add new doc

* add windows batch, comment out root proto

* 1792 fix remote spec handling and hash calculation (#3440)

* fixed bug where nullApi.java would be generated.  Instead, generated DefaultApi.java to match the default path /{pathParam} (#3821)

* Revert "1792 fix remote spec handling and hash calculation (#3440)"

This reverts commit 2a2eefe.

* Add  nickmeinhold to Dart technical committee (#3830)

* Bug #2845 typescript angular inheritance (#3812)

* issue #2845: enable 'supportsMultipleInheritance' on typescript angular client codegen

- note I reran ./bin/openapi3/typescript-angular-petstore-all.sh and no changes occurred.
  this suggests to me that the petstore.yaml sample should be improved to make use of the
  anyOf / allOf / oneOf keywords, in order to better show the effects of changes on generated code.

* issue #2845: run ./bin/openapi3/typescript-angular-petstore-all.sh

* run `mvn clean package && ./bin/typescript-angular-petstore-all.sh`

* revert extranous files

* fix warnings in csharp-netcore client (#3831)

* Add missing files to the form request (#3834)

* [client][go] avoid duplicated reflect imports (#3847)

* Following up for #3440 (1792 fix remote spec handling and hash calculation) (#3826)

* This patch fixes the bug that we cannot access to remote files when checking file updates.
Following up #3440, supporting auth.

* 1792 fix remote spec handling and hash calculation (#3440)

(cherry picked from commit 2a2eefe)

* fix detecting remote file / local file logic while finding the hash file, taking care of IllegalArgumentException for local files.

* add testcase

* Add a link (#3850)

* Add Element AI to the list (#3856)

* maven-plugin-plugin 3.6.0 (#3854)

*  [Java][okhttp-gson] fix failure to deserialize floats (#3846)

* fixed bug where nullApi.java would be generated.  Instead, generated DefaultApi.java to match the default path /{pathParam}

* fix to bug #3157

* update samples

* Adds Http Info To Dart Api (#3851)

* [C++][Pistache] Add missing setter for arrays (#3837)

* [C++][Pistache] Add missing setter for arrays

Fixes #3769

* [C++][Pistache] Update Petstore sample

* typescript-inversify: improve check for required parameters, support multiple media types (#3849)

* [typescript-inversify] Allow falsy parameters

A required parameter to an api method must not be `null` or `undefined`.
It can be any other falsy value, e.g. `""`, `0` or `false` though. This
change makes sure an error is only thrown in the former case and not in
the latter.

* [typescript-inversify] Handle multiple media types

The Accept and Content-Type HTTP headers can contain a list of media
types. Previously all but the first media type in the api definition
were ignored. Now the headers are properly generated.

* [typescript-inversify] Fix http client interface

The api service methods allow the `body` parameter to be optional. The
parameter is then passed to an `IHttpClient`. So it needs to be optional
there as well.
Also fixed the sample implementation `HttpClient`.

Fixes #3618.

* [typescript-inversify] Regenerate Petstore sample

* [typescript-inversify] Use more explicit null check

This does not change the semantic of the generated code, but makes it more explicit.

Co-Authored-By: Esteban Gehring <esteban.gehring@gmail.com>

* [typescript-angular] allow empty string basePath (#3489)

* [typescript-angular] Fixing #2731 - empty string basePath

* typescript-angular: refactor base path configuration

* typescript-angular: refactor base path configuration

* Fix/r/serialization fix and minor 3xx resp fix (#3817)

* fix(qlik): fix for minor serialization bug

* fix(r): add petsore generated classes

* fix(r): indendation fixes

* typescript-axios: Fix baseoptions (#3866)

* Fixed missing baseOptions of typescript-axios.

The typescript-axios template was missing the baseOptions setting when building an API Configuration. Set it.

* update sample.

* re-generate typescript axios samples

* Rename gRPC generator to "protobuf-schema" (#3864)

* rename grpc generator to protobuf-schema

* update doc

* Prepare v4.1.2 release (#3873)

* update samples

* update date

* fix version in readme

* BugFix #2053 Spring Boot fails to parse LocalDate query parameter (#3860)

Adds the format annotation so that Spring is able to serialize OpenApi date/date-time format into LocalDate/OffsetDateTime.

* update doc, samples (#3875)

* update stable release

* Update the batch for Windows

* Add a test snippet

* Update ensure-up-to-date

* Add Nim to README.md

* Ran ensure-up-to-date to pass CircleCI tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants