Skip to content

rust: support repr(int) enum#9967

Closed
yjh0502 wants to merge 1 commit intoOpenAPITools:masterfrom
yjh0502:rust-enum-repr
Closed

rust: support repr(int) enum#9967
yjh0502 wants to merge 1 commit intoOpenAPITools:masterfrom
yjh0502:rust-enum-repr

Conversation

@yjh0502
Copy link
Contributor

@yjh0502 yjh0502 commented Jul 18, 2021

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master, 5.3.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

description

It adds support for integer-typed enums to rust client binding. Here's example schema:

openapi: 3.0.1
info:
  title: test
  version: v1
servers:
  - url: http://127.0.0.1:3000/
paths:
  /testapi:
    post:
      responses:
        '200':
          $ref: '#/components/schemas/Test'
components:
  schemas:
    Test:
      type: integer
      enum:
        - 101
        - 102

output for the schema is as follows:

 #[repr(i64)]
  #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize_repr, Deserialize_repr)]
  pub enum Test {
      _101 = 101,
      _102 = 102,

  }

  impl ToString for Test {
      fn to_string(&self) -> String {
          match self {
              Self::_101 => String::from("101"),
              Self::_102 => String::from("102"),
          }
      }
  }

Current implementation assumes all enums are string-represented so the schema above fails to decode int-encoded enums. This PR adds support for int-typed enums with [repr(i64)].

cc @paladinzh

@wing328
Copy link
Member

wing328 commented Jul 21, 2021

@yjh0502 thanks for the PR.

cc @frol (2017/07) @farcaller (2017/08) @richardwhiuk (2019/07) @paladinzh (2020/05)

@wing328
Copy link
Member

wing328 commented Jul 21, 2021

Tested locally with a spec containing an enum integer and the result is good.

running 1 test
test test_pet ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests petstore-reqwest

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:05 min
[INFO] Finished at: 2021-07-21T16:47:04+08:00
[INFO] ------------------------------------------------------------------------

If no further feedback, I'll merge this on coming Friday.

@wing328 wing328 modified the milestones: 5.2.1, 5.3.0 Aug 17, 2021
@wing328 wing328 modified the milestones: 5.3.0, 5.3.1 Oct 25, 2021
@wing328 wing328 modified the milestones: 5.3.1, 5.4.0 Dec 29, 2021
@wing328 wing328 modified the milestones: 5.4.0, 6.0.0 Jan 31, 2022
@wing328 wing328 modified the milestones: 6.0.0, 6.1.0, 6.0.1 May 26, 2022
@Hinton
Copy link

Hinton commented Jun 17, 2022

@wing328 any possibility of getting this merged? We're currently using the templates from this PR to solve it locally but it would be nice to get it included in the project. Since maintaining templates means we won't get new features automatically.

@wing328 wing328 modified the milestones: 6.0.1, 6.1.0 Jul 5, 2022
@wing328 wing328 modified the milestones: 6.1.0, 6.1.1 Sep 11, 2022
@wing328 wing328 modified the milestones: 6.1.1, 6.2.1 Sep 24, 2022
@wing328 wing328 modified the milestones: 6.2.1, 6.3.0 Nov 1, 2022
@wing328 wing328 removed this from the 6.3.0 milestone Jan 20, 2023
@wing328 wing328 added this to the 6.3.1 milestone Jan 20, 2023
@wing328 wing328 modified the milestones: 6.4.0, 6.5.0 Feb 19, 2023
@wing328 wing328 modified the milestones: 6.5.0, 6.6.0 Apr 1, 2023
@wing328 wing328 modified the milestones: 6.6.0, 7.0.0 May 11, 2023
@wing328 wing328 modified the milestones: 7.0.0, 7.1.0, 7.0.1 Aug 25, 2023
@wing328 wing328 modified the milestones: 7.0.1, 7.1.0 Sep 20, 2023
@wing328 wing328 modified the milestones: 7.1.0, 7.2.0 Nov 13, 2023
@wing328 wing328 modified the milestones: 7.2.0, 7.3.0 Dec 22, 2023
@wing328 wing328 modified the milestones: 7.3.0, 7.4.0 Feb 8, 2024
@wing328 wing328 removed this from the 7.4.0 milestone Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants