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

Feature/#139 OpenAPI query string/path parameter examples #243

Merged
merged 31 commits into from
Oct 1, 2021

Conversation

choipureum
Copy link
Contributor

@choipureum choipureum commented Sep 16, 2021

related issue : #139

This PR can provide examples for query string/path parameters. It is based on the form written on the existing payloadAttribute.

OverView:

  • trigger
 [OpenApiParameter(name: "dateTimeParameter", In = ParameterLocation.Query, Required = true, Example = typeof(DateTimeParameterExample), Type = typeof(DateTime), Description = "The **dateTime** parameter")]
  • model
    public class DateTimeParameterExample : OpenApiExample<DateTime>
    {
        public override IOpenApiExample<DateTime> Build(NamingStrategy namingStrategy = null)
        {
            this.Examples.Add(OpenApiExampleResolver.Resolve("dateTimeValue1", DateTime.Parse("2021-01-01"), namingStrategy));
            this.Examples.Add(OpenApiExampleResolver.Resolve("dateTimeValue2", DateTime.Parse("2021-01-01T12:34:56Z"), namingStrategy));
            return this;
        }
    }
  • openapi.json
          {
            "name": "dateTimeParameter",
            "in": "query",
            "description": "The **dateTime** parameter",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "example": "2021-01-01T00:00:00.0000000+09:00",
            "examples": {
              "dateTimeValue1": {
                "value": "2021-01-01T00:00:00.0000000+09:00"
              },
              "dateTimeValue2": {
                "value": "2021-01-01T21:34:56.0000000+09:00"
              }
            }
          },

choipureum and others added 17 commits August 24, 2021 00:45
Signed-off-by: choipureum <pooreumsunny@gmail.com>
Signed-off-by: choipureum <pooreumsunny@gmail.com>
Signed-off-by: poo <poo1994@hanmail.net>
Signed-off-by: poo <poo1994@hanmail.net>
Signed-off-by: poo <poo1994@hanmail.net>
Signed-off-by: poo <poo1994@hanmail.net>
Signed-off-by: poo <poo1994@hanmail.net>
Signed-off-by: poo <poo1994@hanmail.net>
Signed-off-by: choipureum <pooreumsunny@gmail.com>
Signed-off-by: choipureum <pooreumsunny@gmail.com>
Signed-off-by: choipureum <pooreumsunny@gmail.com>
@justinyoo justinyoo linked an issue Sep 17, 2021 that may be closed by this pull request
Copy link
Contributor

@justinyoo justinyoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I found that we should update OpenApiExampleResolver as well because it assumes only an object is coming in – it always converts the object into an escaped JSON string.

Value = new OpenApiString(JsonConvert.SerializeObject(instance, settings)),

However, with this PR, it SHOULD NOT assume the example is an object.

Depending on the type of the example – string, number, boolean, etc. the example value should be one of OpenApiString, OpenApiInteger, OpenApiBoolean, etc.

Could you have a further look?

@choipureum
Copy link
Contributor Author

I understand. Thank you for the review. I will revise and commit as soon as possible. 😀

@github-actions github-actions bot added the oca-issue For participants from OSS Contribution Academy label Sep 17, 2021
@justinyoo justinyoo added oca-pr For participants from OSS Contribution Academy enhancement New feature or request v0.9.0 labels Sep 17, 2021
Signed-off-by: poo <poo1994@hanmail.net>
Signed-off-by: poo <poo1994@hanmail.net>
Copy link
Contributor

@justinyoo justinyoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your update! I left comments here mainly about declaring your test object types. Please take a further look and update your code in accordance with that.

Please make sure that you're testing all the possible value types.

Signed-off-by: poo <poo1994@hanmail.net>
Signed-off-by: poo <poo1994@hanmail.net>
Signed-off-by: poo <poo1994@hanmail.net>
Copy link
Contributor

@justinyoo justinyoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comprehensive updates! It's almost there.

We've now got DateTime related ones, but not yet DateTimeOffset related ones. Could you please consider the DateTimeOffset related examples, tests, etc?

choipureum and others added 3 commits October 1, 2021 11:48
Signed-off-by: ChoiPuReum <pooreumsunny@gmail.com>
Signed-off-by: ChoiPuReum <pooreumsunny@gmail.com>
Copy link
Contributor

@justinyoo justinyoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for your contribution!

@justinyoo justinyoo merged commit 7d1b47f into Azure:main Oct 1, 2021
meanstigerkim pushed a commit to meanstigerkim/azure-functions-openapi-extension that referenced this pull request Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request oca-issue For participants from OSS Contribution Academy oca-pr For participants from OSS Contribution Academy v0.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenAPI query string/path parameter examples
2 participants