MCPcopy Index your code
hub / github.com/rilldata/rill / parseAPI

Method parseAPI

runtime/parser/parse_api.go:29–128  ·  view source on GitHub ↗

parseAPI parses an API definition and adds the resulting resource to p.Resources.

(node *Node)

Source from the content-addressed store, hash-verified

27
28// parseAPI parses an API definition and adds the resulting resource to p.Resources.
29func (p *Parser) parseAPI(node *Node) error {
30 // Parse YAML
31 tmp := &APIYAML{}
32 err := p.decodeNodeYAML(node, false, tmp)
33 if err != nil {
34 return err
35 }
36
37 // Validate
38 var openapiSummary, openapiParams, openapiRequestSchema, openapiResponseSchema, openapiDefsPrefix string
39 if tmp.OpenAPI != nil {
40 openapiSummary = tmp.OpenAPI.Summary
41
42 if len(tmp.OpenAPI.Parameters) != 0 {
43 paramsJSON, err := json.Marshal(tmp.OpenAPI.Parameters)
44 if err != nil {
45 return fmt.Errorf("invalid openapi.parameters: %w", err)
46 }
47 _, err = openapiutil.ParseJSONParameters(string(paramsJSON))
48 if err != nil {
49 return fmt.Errorf("invalid openapi.parameters: %w", err)
50 }
51 openapiParams = string(paramsJSON)
52 }
53
54 if len(tmp.OpenAPI.RequestSchema) != 0 {
55 requestSchemaJSON, err := json.Marshal(tmp.OpenAPI.RequestSchema)
56 if err != nil {
57 return fmt.Errorf("invalid openapi.request_schema: %w", err)
58 }
59 _, _, err = openapiutil.ParseJSONSchema(node.Name, string(requestSchemaJSON))
60 if err != nil {
61 return fmt.Errorf("invalid openapi.request_schema: %w", err)
62 }
63 openapiRequestSchema = string(requestSchemaJSON)
64 }
65
66 if len(tmp.OpenAPI.ResponseSchema) != 0 {
67 responseSchemaJSON, err := json.Marshal(tmp.OpenAPI.ResponseSchema)
68 if err != nil {
69 return fmt.Errorf("invalid openapi.response_schema: %w", err)
70 }
71 _, _, err = openapiutil.ParseJSONSchema(node.Name, string(responseSchemaJSON))
72 if err != nil {
73 return fmt.Errorf("invalid openapi.response_schema: %w", err)
74 }
75 openapiResponseSchema = string(responseSchemaJSON)
76 }
77
78 if tmp.OpenAPI.DefsPrefix == nil {
79 // Default to the API name in PascalCase
80 openapiDefsPrefix = toPascalCase(node.Name)
81 } else {
82 openapiDefsPrefix = *tmp.OpenAPI.DefsPrefix
83 }
84 }
85
86 // Map common node properties to DataYAML

Callers 1

parseNodeMethod · 0.95

Calls 9

decodeNodeYAMLMethod · 0.95
parseDataYAMLMethod · 0.95
insertResourceMethod · 0.95
ParseJSONParametersFunction · 0.92
ParseJSONSchemaFunction · 0.92
toPascalCaseFunction · 0.85
GetAccessMethod · 0.80
ErrorfMethod · 0.65
ProtoMethod · 0.45

Tested by

no test coverage detected