logto-io / logto

🧑‍🚀 The better identity infrastructure for developers and the open-source alternative to Auth0.
https://logto.io
Mozilla Public License 2.0
8.15k stars 395 forks source link

feat: add content schema to HTTP 201 CREATED messages #6244

Closed mostafa closed 1 month ago

mostafa commented 1 month ago

Summary

When creating a new organization using the Go SDK that I generated from the OpenAPI spec doc, go-api-client, the CreateOrganization endpoint returns a 201 CREATED HTTP status code and an Organization instance with a populated ID field (of the new org). However, the schema doesn't exist in the content key of the response:

image

This results in a normal http.Response object to be returned in Go, instead of an instance of a struct, which is unlike other endpoints that return a processed schema as an object. If the content key is added to the response of 201 status codes, it'll result in the processing of the resp (below) into a separate instance of the (generated) Organization struct and I can access the newOrg like an object: newOrg.GetId(). In the existing case, I need to unmarshal the body of the response into a map[string]any (JSON) object to be able to access the ID field.

- resp, err := client.OrganizationsAPI.CreateOrganization(ctx).CreateOrganizationRequest(createOrgReq).Execute()
+ newOrg, _, err := client.OrganizationsAPI.CreateOrganization(ctx).CreateOrganizationRequest(createOrgReq).Execute()

Testing

Access the swagger.json endpoint and see if the 201 status of the POST request of the /api/organizations has response.content.

Note to Reviewer

  1. I was able to test the updated response with 201 HTTP status code and this is the result:

image

  1. I'd be happy to donate go-api-client to you, if you want. I just need to make some changes after transferring the project.

Checklist

github-actions[bot] commented 1 month ago

COMPARE TO master

Total Size Diff :chart_with_upwards_trend: +18 Bytes

Diff by File |Name|Diff| |---|---| |packages/core/src/routes/swagger/index.ts|:chart_with_upwards_trend: +18 Bytes|
gao-sun commented 1 month ago

I'd be happy to donate go-api-client to you, if you want. I just need to make some changes after transferring the project.

@mostafa thank you for all your great contribution! we can create an awesome list for community projects thus the project. can still belong to you and it can get exposure

gao-sun commented 1 month ago

@mostafa i'm adding your project link in #6297