From 48e17d10f1ed25ab7bee7e21ecec7a916b5f0a43 Mon Sep 17 00:00:00 2001 From: Jakub Pavlik Date: Wed, 12 Jun 2024 20:11:15 +0200 Subject: [PATCH 1/2] support resources with collection actions only i.e. no resource/member actions --- app/models/graphiti/open_api/endpoint.rb | 4 +- spec/fixtures/files/schema_basic.json | 66 ++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/app/models/graphiti/open_api/endpoint.rb b/app/models/graphiti/open_api/endpoint.rb index b951f0f..f3b2bd9 100644 --- a/app/models/graphiti/open_api/endpoint.rb +++ b/app/models/graphiti/open_api/endpoint.rb @@ -28,7 +28,7 @@ def paths }.merge(collection_actions.map(&:operation).inject(&:merge)), resource_path => { parameters: [{'$ref': "#/components/parameters/#{resource.type}_id"}] + parameters, - }.merge(resource_actions.map(&:operation).inject(&:merge)), + }.merge(resource_actions.map(&:operation).inject({}, &:merge)), } end @@ -52,7 +52,7 @@ def parameters end def resource - resource_actions.first.resource + actions.first.resource end def_instance_delegators :resource, :type diff --git a/spec/fixtures/files/schema_basic.json b/spec/fixtures/files/schema_basic.json index af918e3..2954b2f 100644 --- a/spec/fixtures/files/schema_basic.json +++ b/spec/fixtures/files/schema_basic.json @@ -67,6 +67,65 @@ "count" ] } + }, + { + "name": "CreateOnlyResource", + "type": "create_only_entities", + "graphql_entrypoint": "create_only_entities", + "description": "Resource supporting only the create action.", + "attributes": { + "id": { + "type": "integer_id", + "readable": true, + "writable": true, + "description": null + }, + "label": { + "type": "string", + "readable": true, + "writable": true, + "description": null + } + }, + "extra_attributes": {}, + "sorts": { + "id": {}, + "label": {} + }, + "filters": { + "id": { + "type": "integer_id", + "operators": [ + "eq", + "not_eq", + "gt", + "gte", + "lt", + "lte" + ] + }, + "label": { + "type": "string", + "operators": [ + "eq", + "not_eq", + "eql", + "not_eql", + "prefix", + "not_prefix", + "suffix", + "not_suffix", + "match", + "not_match" + ] + } + }, + "relationships": {}, + "stats": { + "total": [ + "count" + ] + } } ], "endpoints": { @@ -79,6 +138,13 @@ "resource": "EntityResource" } } + }, + "/api/v1/create_only_entities": { + "actions": { + "create": { + "resource": "CreateOnlyResource" + } + } } }, "types": { From fec68e8859b6ba21789c819ad7b4c1efe223c358 Mon Sep 17 00:00:00 2001 From: Jakub Pavlik Date: Wed, 12 Jun 2024 20:19:18 +0200 Subject: [PATCH 2/2] support resources with resource/member actions only i.e. no collection actions --- app/models/graphiti/open_api/endpoint.rb | 2 +- spec/fixtures/files/schema_basic.json | 68 +++++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/app/models/graphiti/open_api/endpoint.rb b/app/models/graphiti/open_api/endpoint.rb index f3b2bd9..16c4653 100644 --- a/app/models/graphiti/open_api/endpoint.rb +++ b/app/models/graphiti/open_api/endpoint.rb @@ -25,7 +25,7 @@ def paths { path => { parameters: parameters, - }.merge(collection_actions.map(&:operation).inject(&:merge)), + }.merge(collection_actions.map(&:operation).inject({}, &:merge)), resource_path => { parameters: [{'$ref': "#/components/parameters/#{resource.type}_id"}] + parameters, }.merge(resource_actions.map(&:operation).inject({}, &:merge)), diff --git a/spec/fixtures/files/schema_basic.json b/spec/fixtures/files/schema_basic.json index 2954b2f..a48e8c0 100644 --- a/spec/fixtures/files/schema_basic.json +++ b/spec/fixtures/files/schema_basic.json @@ -71,7 +71,7 @@ { "name": "CreateOnlyResource", "type": "create_only_entities", - "graphql_entrypoint": "create_only_entities", + "graphql_entrypoint": "createOnlyEntities", "description": "Resource supporting only the create action.", "attributes": { "id": { @@ -126,6 +126,65 @@ "count" ] } + }, + { + "name": "ShowOnlyResource", + "type": "show_only_entities", + "graphql_entrypoint": "showOnlyEntities", + "description": "Resource supporting only the show action.", + "attributes": { + "id": { + "type": "integer_id", + "readable": true, + "writable": true, + "description": null + }, + "label": { + "type": "string", + "readable": true, + "writable": true, + "description": null + } + }, + "extra_attributes": {}, + "sorts": { + "id": {}, + "label": {} + }, + "filters": { + "id": { + "type": "integer_id", + "operators": [ + "eq", + "not_eq", + "gt", + "gte", + "lt", + "lte" + ] + }, + "label": { + "type": "string", + "operators": [ + "eq", + "not_eq", + "eql", + "not_eql", + "prefix", + "not_prefix", + "suffix", + "not_suffix", + "match", + "not_match" + ] + } + }, + "relationships": {}, + "stats": { + "total": [ + "count" + ] + } } ], "endpoints": { @@ -145,6 +204,13 @@ "resource": "CreateOnlyResource" } } + }, + "/api/v1/show_only_entities": { + "actions": { + "show": { + "resource": "ShowOnlyResource" + } + } } }, "types": {