-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider path parameters common to all operations (#148)
Also: * Ensure there is no oneOf definition before defaulting to a simple type * Exclude id property from required outputs copied from response body schema. Handle property type if its ref is to a schema with a oneOf definition * Sanitize names that contain HTTP verbs
- Loading branch information
1 parent
3c2683d
commit 04e99a6
Showing
5 changed files
with
154 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package pkg | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestCommonPathParams tests if path params that are | ||
// common to all operations are considered. | ||
func TestCommonPathParams(t *testing.T) { | ||
mustReadTestOpenAPIDoc(t, filepath.Join("testdata", "common_path_params_openapi.yml")) | ||
|
||
openAPICtx := &OpenAPIContext{ | ||
Doc: *testOpenAPIDoc, | ||
Pkg: &testPulumiPkg, | ||
} | ||
|
||
csharpNamespaces := map[string]string{ | ||
"": "Provider", | ||
} | ||
|
||
_, _, err := openAPICtx.GatherResourcesFromAPI(csharpNamespaces) | ||
assert.Nil(t, err) | ||
|
||
subResource, ok := testPulumiPkg.Resources["fake-package:fakeresource/v2:SubResource"] | ||
assert.Truef(t, ok, "Expected to find a resource called SubResource: %v", testPulumiPkg.Resources) | ||
|
||
// Ensure that the input properties for the resource contains | ||
// the expected id property. | ||
assert.Contains(t, subResource.InputProperties, "id") | ||
|
||
// Ensure that the "get" func also contains the id | ||
// as an input properties. | ||
getFunc, ok := testPulumiPkg.Functions["fake-package:fakeresource/v2:listSubResources"] | ||
assert.Truef(t, ok, "Expected to find a list func listSubResources: %v", testPulumiPkg.Functions) | ||
assert.NotNil(t, getFunc.Inputs) | ||
assert.Contains(t, getFunc.Inputs.Properties, "id") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
openapi: 3.1.0 | ||
info: | ||
title: Fake API | ||
version: "2.0" | ||
servers: | ||
- url: https://api.fake.com | ||
description: production | ||
|
||
components: | ||
schemas: | ||
a_string_prop: | ||
type: string | ||
request_object_type: | ||
type: object | ||
properties: | ||
simple_prop: | ||
$ref: "#/components/schemas/a_string_prop" | ||
response_object_type: | ||
type: object | ||
properties: | ||
another_prop: | ||
$ref: "#/components/schemas/a_string_prop" | ||
|
||
paths: | ||
/v2/fakeResource/{id}/subResource: | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
get: | ||
operationId: listSubResources | ||
responses: | ||
"200": | ||
description: The response will be a JSON object with a key called `subResources` which is an array of sub-resource items. | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
subResources: | ||
type: array | ||
items: | ||
$ref: "#/components/schemas/response_object_type" | ||
post: | ||
operationId: createSubResource | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/request_object_type" | ||
responses: | ||
"200": | ||
description: The response will be a JSON object with a key called `action`. | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/response_object_type" |