-
Notifications
You must be signed in to change notification settings - Fork 170
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
API Skeleton 2021-01-31 - swagger #1200
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking pretty plausible to me. Let's catch up on this tomorrow.
Please rebase pull request. |
e05269f
to
b3b0a69
Compare
61479b8
to
e7bf5d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a lot of nits - please fix out and we'll merge.
Converters and changes to internal API are missing here - OK with those being in a follow-up PR.
pkg/util/azureclient/mgmt/redhatopenshift/2021-01-31-preview/redhatopenshift/operations.go
Outdated
Show resolved
Hide resolved
020f3fd
to
c0a5aea
Compare
Azure/azure-rest-api-specs#12144 upstream review |
We had an issue with systemData. I interpreted this as a mandatory field on the main object we return. Hence adding it to the In addition, added |
52c59bc
to
d70bf42
Compare
@jim-minter, the last commit will require your attention. |
pkg/api/v20210131preview/openshiftclusteradminkubeconfig_example.go
Outdated
Show resolved
Hide resolved
eeec873
to
e4ae89f
Compare
var _ generator = &apiv20200430{} | ||
|
||
type features struct { | ||
kubeconfig bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed - test if ExampleOpenShiftClusterAdminKubeconfigResponse is non-nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easier to read and easier to understand. As much as it is possible I think consistency is better if we keep same behavior (feature flags). Otherwise some of them will be "flags, some function checks". Unreadable and insiders knowledge.
pkg/swagger/generator.go
Outdated
systemData bool | ||
} | ||
|
||
type apiv20210131preview struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is pretty over engineered - you could probably simplify and get away with a static configuration like this:
type api struct {
exampleOpenShiftClusterPutParameter func() interface{}
exampleOpenShiftClusterPatchParameter func() interface{}
exampleOpenShiftClusterResponse func() interface{}
exampleOpenShiftClusterCredentialsResponse func() interface{}
exampleOpenShiftClusterAdminKubeconfigResponse func() interface{}
exampleOpenShiftClusterListResponse func() interface{}
exampleOperationListResponse func() interface{}
xmsEnum []string
commonTypesVersion string
systemData bool
}
var apis = map[string]*api {
apiv20200430Path: {
exampleOpenShiftClusterPutParameter: v20200430.ExampleOpenShiftClusterPutParameter,
// ...
},
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do this in go?
cannot use v20200430.ExampleOpenShiftClusterPutParameter (value of type func() *v20200430.OpenShiftCluster) as func() interface{} value in struct literal
was sitting on this for 2 hours trying to understand what you had in mind here....
foo func() interface{}
!=
func foo() *Custom{
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before I start refactoring for 4th time I would like to understand if Im missing something here for this to work (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caught my curiosity and found this interesting answer.
https://stackoverflow.com/a/54751503
I still need to see if the same applies to return values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjudeikis I'm inclined to do the horrible thing and make all the Example*() functions return interface{}. It's rubbish but it's a lot less boilerplate.
@@ -73,16 +93,18 @@ func Run(api, outputDir string) error { | |||
|
|||
xmsEnumList := map[string]struct{}{} | |||
|
|||
if api != "github.com/Azure/ARO-RP/pkg/api/v20200430" { | |||
names := []string{"OpenShiftClusterList", "OpenShiftClusterCredentials"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a lot of the code around here could be more neatly parameterised and defined in g
...ft.RedHatOpenShift/preview/2021-01-31-preview/examples/OpenShiftClusters_CreateOrUpdate.json
Outdated
Show resolved
Hide resolved
pkg/swagger/swagger.go
Outdated
@@ -126,6 +148,19 @@ func Run(api, outputDir string) error { | |||
} | |||
|
|||
s.Definitions[azureResource].Properties = properties | |||
|
|||
if g.Features().systemData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't look right. I think it is masking the fact that we actually need to add this to the model and deal with it. See https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/common-api-contracts.md#system-metadata-for-all-azure-resources
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added separate PR for this. Sill in draft, but working on it #1412
@@ -164,6 +164,7 @@ type Response struct { | |||
Schema *Schema `json:"schema,omitempty"` | |||
Headers Headers `json:"headers,omitempty"` | |||
Examples Example `json:"examples,omitempty"` | |||
SystemData *Schema `json:"systemData,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ARM CI/sign-off required this for all new APIs/API Versions. I think we will need to make change not to log this in any away in our code but overall we need it now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that I understand - how is it related to the response object?
bump - there's a longstanding unactioned review here |
@@ -126,6 +142,19 @@ func Run(api, outputDir string) error { | |||
} | |||
|
|||
s.Definitions[azureResource].Properties = properties | |||
|
|||
if g.systemData { | |||
s.Definitions[azureResource].Properties = append(s.Definitions[azureResource].Properties, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wondering if this is right?
/azp run e2e |
Azure Pipelines successfully started running 1 pipeline(s). |
Please rebase pull request. |
/azp run e2e |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run e2e |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run e2e |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how you introduced support for generating multiple api versions and their examples, but I'm not sure that changes related to systemData
and admin kube config are correct. For instance this PR introduces a new endpoint to list the admin kube config. Are we ready to make this decision?
I'm up for merging the generator part, but not sure that I'm comfortable with placeholders for new features and related swagger generation changes. If you want - we can split this into multiple pull requests so we can merge the generator part faster.
@@ -164,6 +164,7 @@ type Response struct { | |||
Schema *Schema `json:"schema,omitempty"` | |||
Headers Headers `json:"headers,omitempty"` | |||
Examples Example `json:"examples,omitempty"` | |||
SystemData *Schema `json:"systemData,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that I understand - how is it related to the response object?
}, | ||
} | ||
if g.kubeconfig { | ||
s.Paths["/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RedHatOpenShift/openShiftClusters/{resourceName}/listAdminCredentials"] = &PathItem{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implies that we will have another endpoint (and another az
cli command) to get admin kubeconfig. Why not extend existing command/endpoint for the new verson?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this will be different endpoint and API. Few reasons for this:
- Prevent api breakage for old API
- API purpose is different as it will download file, and not expose
- Easier to implement.
- It will return privileged kubeconfig so in the future dedicated rbac could be added
@@ -24,7 +29,7 @@ func Run(api, outputDir string) error { | |||
Schemes: []string{"https"}, | |||
Consumes: []string{"application/json"}, | |||
Produces: []string{"application/json"}, | |||
Paths: populateTopLevelPaths("Microsoft.RedHatOpenShift", "openShiftCluster", "OpenShift cluster"), | |||
Paths: g.populateTopLevelPaths("Microsoft.RedHatOpenShift", "openShiftCluster", "OpenShift cluster"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put resourceProviderNamespace
as a parameter into generator
struct so we don't have to pass it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not on this PR, or one if follow-up. Too much change.
Responses: g.populateResponses("OpenShiftClusterAdminKubeconfig", false, http.StatusOK), | ||
}, | ||
} | ||
} | ||
|
||
s.Paths["/providers/Microsoft.RedHatOpenShift/operations"] = &PathItem{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to move listCredentials
, listAdminCredentials
(if we actually need it, see the question above) and operations
paths somewhere into generator
. Similarly to populateTopLevelPaths
.
And probably all logic from Run
into generator so the whole Run
function will be something like:
g, err := New(api, params1, param2)
if err != nil {
return err
}
s := g.Swagger()
b, err := json.MarshalIndent(s, "", " ")
if err != nil {
return err
}
b = append(b, '\n')
return ioutil.WriteFile(outputDir+"/redhatopenshift.json", b, 0666)
But I think it should be a separate PR: this one is already too big.
I think I gonna split the PRs as you suggest. Initially placeholder where there to kick start arm review process on API so could do implementation in parallel. We still need to do this, but maybe separate PR. |
will re-open in smallers prs |
This is just a skeleton builds on top of #1191
This PR does: