diff --git a/pkg/concepts/type.go b/pkg/concepts/type.go index e54dee6..8a67a6b 100644 --- a/pkg/concepts/type.go +++ b/pkg/concepts/type.go @@ -164,6 +164,14 @@ func (t *Type) IsScalar() bool { return t.kind == ScalarType || t.kind == EnumType || t.kind == InterfaceType } +func (t *Type) IsBasicType() bool { + if t == nil { + return false + } + + return t.kind == ScalarType +} + // IsStruct returns true iff this type is an struct type. Note that class types are also considered // struct types. func (t *Type) IsStruct() bool { diff --git a/pkg/generators/golang/types_calculator.go b/pkg/generators/golang/types_calculator.go index e5d9b91..f8f84be 100644 --- a/pkg/generators/golang/types_calculator.go +++ b/pkg/generators/golang/types_calculator.go @@ -239,6 +239,7 @@ func (c *TypesCalculator) ValueReference(typ *concepts.Type) *TypeReference { "Don't know how to calculate value reference for type '%s'", typ, ) + ref = &TypeReference{} } return ref diff --git a/pkg/language/reader.go b/pkg/language/reader.go index 9ee8e29..c388c32 100644 --- a/pkg/language/reader.go +++ b/pkg/language/reader.go @@ -22,6 +22,7 @@ package language import ( "fmt" "io/ioutil" + "log" "os" "path/filepath" "strconv" @@ -144,7 +145,7 @@ func (r *Reader) Read() (model *concepts.Model, err error) { version.AddType(listType) } else { // The list type was previously defined from a cross reference. - // we thus need to redefine it. + // we thus need to override its owner it. listType.SetOwner(version) } } @@ -155,6 +156,19 @@ func (r *Reader) Read() (model *concepts.Model, err error) { // Run checks: r.checkModel() + for _, service := range r.model.Services() { + for _, version := range service.Versions() { + fmt.Printf("-------------- Version: %s -------------- \n", version.Name().String()) + for _, typ := range version.Types() { + log.Printf("type: %s, version: %s, owner: %s", + typ.Name().String(), + version.Name().String(), + typ.Owner().Name().String(), + ) + } + } + } + // Check if there are errors: errors := r.reporter.Errors() if errors > 0 { @@ -484,15 +498,16 @@ func (r *Reader) handleClassRef(typ *concepts.Type, path string) { // A helper function to recursively add types to a version func (r *Reader) recursivelyAddTypeToVersion(currType *concepts.Type, referencedType *concepts.Type) { + if referencedType.IsBasicType() { + return + } for _, attribute := range referencedType.Attributes() { if attribute.Link() { r.version.AddTypeWithoutOwner(attribute.Type()) - } - if attribute.Type().IsList() || attribute.Type().IsMap() { - r.version.AddTypeWithoutOwner(attribute.Type()) - r.version.AddTypeWithoutOwner(attribute.Type().Element()) - } - if r.version.FindType(attribute.Type().Name()) == nil { + } else if attribute.Type().IsList() || attribute.Type().IsMap() { + r.recursivelyAddTypeToVersion(currType, attribute.Type()) + r.recursivelyAddTypeToVersion(currType, attribute.Type().Element()) + } else if r.version.FindType(attribute.Type().Name()) == nil { r.recursivelyAddTypeToVersion(currType, attribute.Type()) } } diff --git a/tests/model/aro_hcp/v1_alpha1/cluster_resource.model b/tests/model/aro_hcp/v1_alpha1/cluster_resource.model new file mode 100644 index 0000000..d45afaa --- /dev/null +++ b/tests/model/aro_hcp/v1_alpha1/cluster_resource.model @@ -0,0 +1,42 @@ +/* +Copyright (c) 2024 Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Manages a specific cluster. +resource Cluster { + // Retrieves the details of the cluster. + method Get { + out Body Cluster + } + + // Updates the cluster. + method Update { + in out Body Cluster + } + + // Deletes the cluster. + method Delete { + // Dry run flag is used to check if the operation can be completed, but won't delete. + in DryRun Boolean = false + + // BestEffort flag is used to check if the cluster deletion should be best-effort mode or not. + in BestEffort Boolean = false + } + + // Reference to the resource that manages the collection of node pool resources. + locator NodePools { + target NodePools + } +} \ No newline at end of file diff --git a/tests/model/aro_hcp/v1_alpha1/cluster_type.model b/tests/model/aro_hcp/v1_alpha1/cluster_type.model new file mode 100644 index 0000000..793cc1f --- /dev/null +++ b/tests/model/aro_hcp/v1_alpha1/cluster_type.model @@ -0,0 +1,19 @@ +/* +Copyright (c) 2024 Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +@ref(path = "/clusters_mgmt/v1/cluster") +class Cluster { +} \ No newline at end of file diff --git a/tests/model/aro_hcp/v1_alpha1/clusters_resource.model b/tests/model/aro_hcp/v1_alpha1/clusters_resource.model new file mode 100644 index 0000000..136b081 --- /dev/null +++ b/tests/model/aro_hcp/v1_alpha1/clusters_resource.model @@ -0,0 +1,79 @@ +/* +Copyright (c) 2024 Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Manages the collection of aro_hcp clusters. +resource Clusters { + // Retrieves the list of clusters. + method List { + // Index of the requested page, where one corresponds to the first page. + in out Page Integer = 1 + + // Maximum number of items that will be contained in the returned page. + in out Size Integer = 100 + + // Search criteria. + // + // The syntax of this parameter is similar to the syntax of the _where_ clause of a + // SQL statement, but using the names of the attributes of the cluster instead of + // the names of the columns of a table. For example, in order to retrieve all the + // clusters with a name starting with `my` in the `us-east-1` region the value + // should be: + // + // ```sql + // name like 'my%' and region.id = 'us-east-1' + // ``` + // + // If the parameter isn't provided, or if the value is empty, then all the + // clusters that the user has permission to see will be returned. + in Search String + + // Order criteria. + // + // The syntax of this parameter is similar to the syntax of the _order by_ clause of + // a SQL statement, but using the names of the attributes of the cluster instead of + // the names of the columns of a table. For example, in order to sort the clusters + // descending by region identifier the value should be: + // + // ```sql + // region.id desc + // ``` + // + // If the parameter isn't provided, or if the value is empty, then the order of the + // results is undefined. + in Order String + + // Total number of items of the collection that match the search criteria, + // regardless of the size of the page. + out Total Integer + + // Retrieved list of clusters. + out Items []Cluster + } + + // Provision a new cluster and add it to the collection of clusters. + // + // See the `register_cluster` method for adding an existing cluster. + method Add { + // Description of the cluster. + in out Body Cluster + } + + // Returns a reference to the service that manages an specific cluster. + locator Cluster { + target Cluster + variable ID + } +} \ No newline at end of file diff --git a/tests/model/aro_hcp/v1_alpha1/node_pool_resource.model b/tests/model/aro_hcp/v1_alpha1/node_pool_resource.model new file mode 100644 index 0000000..018e7ec --- /dev/null +++ b/tests/model/aro_hcp/v1_alpha1/node_pool_resource.model @@ -0,0 +1,32 @@ +/* +Copyright (c) 2024 Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Manages a specific nodepool. +resource NodePool { + // Retrieves the details of the node pool. + method Get { + out Body NodePool + } + + // Updates the node pool. + method Update { + in out Body NodePool + } + + // Deletes the node pool. + method Delete { + } +} diff --git a/tests/model/aro_hcp/v1_alpha1/node_pool_type.model b/tests/model/aro_hcp/v1_alpha1/node_pool_type.model new file mode 100644 index 0000000..c94a048 --- /dev/null +++ b/tests/model/aro_hcp/v1_alpha1/node_pool_type.model @@ -0,0 +1,19 @@ +/* +Copyright (c) 2024 Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +@ref(path = "/clusters_mgmt/v1/node_pool") +class NodePool { +} \ No newline at end of file diff --git a/tests/model/aro_hcp/v1_alpha1/node_pools_resource.model b/tests/model/aro_hcp/v1_alpha1/node_pools_resource.model new file mode 100644 index 0000000..09c370b --- /dev/null +++ b/tests/model/aro_hcp/v1_alpha1/node_pools_resource.model @@ -0,0 +1,75 @@ +/* +Copyright (c) 2022 Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Manages the collection of node pools of a cluster. +resource NodePools { + // Retrieves the list of node pools. + method List { + // Index of the requested page, where one corresponds to the first page. + in out Page Integer = 1 + + // Number of items contained in the returned page. + in out Size Integer = 100 + + // Search criteria. + // + // The syntax of this parameter is similar to the syntax of the _where_ clause of a + // SQL statement, but using the names of the attributes of the node pools instead of + // the names of the columns of a table. For example, in order to retrieve all the + // node pools with replicas of two the following is required: + // + // ```sql + // replicas = 2 + // ``` + // + // If the parameter isn't provided, or if the value is empty, then all the + // node pools that the user has permission to see will be returned. + in Search String + + // Order criteria. + // + // The syntax of this parameter is similar to the syntax of the _order by_ clause of + // a SQL statement, but using the names of the attributes of the node pools instead of + // the names of the columns of a table. For example, in order to sort the node pools + // descending by identifier the value should be: + // + // ```sql + // id desc + // ``` + // + // If the parameter isn't provided, or if the value is empty, then the order of the + // results is undefined. + in Order String + + // Total number of items of the collection. + out Total Integer + + // Retrieved list of node pools. + out Items []NodePool + } + + // Adds a new node pool to the cluster. + method Add { + // Description of the node pool + in out Body NodePool + } + + // Reference to the service that manages a specific node pool. + locator NodePool { + target NodePool + variable ID + } +} \ No newline at end of file diff --git a/tests/model/aro_hcp/v1_alpha1/root_resource.model b/tests/model/aro_hcp/v1_alpha1/root_resource.model new file mode 100644 index 0000000..178bd3b --- /dev/null +++ b/tests/model/aro_hcp/v1_alpha1/root_resource.model @@ -0,0 +1,18 @@ +/* +Copyright (c) 2024 Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Root of the tree of resources of the aro_hcp service. +resource Root {} diff --git a/tests/model/clusters_mgmt/v1/node_pool_type.model b/tests/model/clusters_mgmt/v1/node_pool_type.model new file mode 100644 index 0000000..9c64ffa --- /dev/null +++ b/tests/model/clusters_mgmt/v1/node_pool_type.model @@ -0,0 +1,17 @@ +/* +Copyright (c) 2024 Red Hat, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +Class NodePool {} \ No newline at end of file