From 45150956e400762031fc2c3ff624dd3b9b0b50f5 Mon Sep 17 00:00:00 2001 From: Yash Sharma Date: Thu, 23 Jan 2025 22:11:51 +0530 Subject: [PATCH 1/2] Added Open API schemas for org Signed-off-by: Yash Sharma --- schemas/constructs/openapi/organization.yml | 257 ++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 schemas/constructs/openapi/organization.yml diff --git a/schemas/constructs/openapi/organization.yml b/schemas/constructs/openapi/organization.yml new file mode 100644 index 0000000000..5748db671c --- /dev/null +++ b/schemas/constructs/openapi/organization.yml @@ -0,0 +1,257 @@ +openapi: 3.0.0 +info: + title: Meshery Cloud + description: Documentation for meshery Cloud REST APIs + contact: + email: support@layer5.io + version: v0.6.394 +servers: + - url: https://meshery.layer5.io + description: Meshery Cloud production server URL + - url: https://staging-meshery.layer5.io + description: Meshery Cloud staging server URL + - url: http://localhost:9876 + description: Meshery Cloud development server URL (controlled via PORT environment variable) +security: + - jwt: [] +tags: + - name: organizations + description: Workspaces bring teams, environments, and designs together +components: + securitySchemes: + jwt: + type: http + scheme: Bearer + bearerFormat: JWT + schemas: + organizationWithRoles: + type: object + properties: + ID: + $ref: ./common/core.yml#/components/schemas/general_id + name: + $ref: ./common/core.yml#/components/schemas/text + description: + $ref: ./common/core.yml#/components/schemas/text + country: + $ref: ./common/core.yml#/components/schemas/text + region: + $ref: ./common/core.yml#/components/schemas/text + owner: + type: string + format: uuid + x-go-type: uuid.UUID + x-go-type-import: + path: github.com/gofrs/uuid + x-oapi-codegen-extra-tags: + db: owner + json: owner + x-go-type-skip-optional-pointer: true + metadata: + $ref: '#/components/schemas/organizationMetadata' + created_at: + $ref: ./common/core.yml#/components/schemas/time + updated_at: + $ref: ./common/core.yml#/components/schemas/time + deleted_at: + $ref: ./common/core.yml#/components/schemas/nullTime + role_names: + $ref: '#/components/schemas/roleNames' + availableOrganization: + type: object + properties: + ID: + $ref: ./common/core.yml#/components/schemas/general_id + name: + $ref: ./common/core.yml#/components/schemas/text + description: + $ref: ./common/core.yml#/components/schemas/text + country: + $ref: ./common/core.yml#/components/schemas/text + region: + $ref: ./common/core.yml#/components/schemas/text + owner: + $ref: ./common/core.yml#/components/schemas/text + description: UserID of user who created organization + metadata: + $ref: '#/components/schemas/organizationMetadata' + created_at: + $ref: ./common/core.yml#/components/schemas/time + updated_at: + $ref: ./common/core.yml#/components/schemas/time + deleted_at: + $ref: ./common/core.yml#/components/schemas/nullTime + organizationMetadata: + type: object + properties: + preferences: + $ref: '#/components/schemas/organizationPreferences' + organizationPreferences: + type: object + properties: + theme: + type: object + properties: + theme_id: + type: string + description: ID for the theme to load for the currently selected organization + logo: + type: object + properties: + desktop_view: + type: string + description: Contains the location of the custom desktop view SVG. + mobile_view: + type: string + description: Contains the location of the custom mobile view SVG. + dashboard: + type: object + properties: + layout: + additionalProperties: + type: object + organization: + properties: + ID: + $ref: ./common/core.yml#/components/schemas/general_id + name: + $ref: ./common/core.yml#/components/schemas/text + country: + $ref: ./common/core.yml#/components/schemas/text + region: + $ref: ./common/core.yml#/components/schemas/text + owner: + type: string + format: uuid + x-go-type: uuid.UUID + x-go-type-import: + path: github.com/gofrs/uuid + x-oapi-codegen-extra-tags: + db: owner + json: owner + x-go-type-skip-optional-pointer: true + metadata: + $ref: '#/components/schemas/organizationMetadata' + created_at: + $ref: ./common/core.yml#/components/schemas/time + updated_at: + $ref: ./common/core.yml#/components/schemas/time + deleted_at: + $ref: ./common/core.yml#/components/schemas/nullTime + required: + - name + organizationsPage: + properties: + page: + type: ./common/core.yml#/components/schemas/number + page_size: + type: ./common/core.yml#/components/schemas/number + total_count: + type: ./common/core.yml#/components/schemas/number + organizations: + type: array + items: + $ref: '#/components/schemas/availableOrganization' + organizationPayload: + properties: + name: + $ref: ./common/core.yml#/components/schemas/text + country: + $ref: ./common/core.yml#/components/schemas/text + region: + $ref: ./common/core.yml#/components/schemas/text + description: + $ref: ./common/core.yml#/components/schemas/text + notify_org_update: + type: boolean + preferences: + $ref: '#/components/schemas/organizationPreferences' + teamsOrganizationsMapping: + properties: + ID: + $ref: ./common/core.yml#/components/schemas/general_id + org_id: + type: string + format: uuid + x-go-type: uuid.UUID + x-go-type-import: + path: github.com/gofrs/uuid + x-oapi-codegen-extra-tags: + db: org_id + json: org_id + x-go-type-skip-optional-pointer: true + team_id: + type: string + format: uuid + x-go-type: uuid.UUID + x-go-type-import: + path: github.com/gofrs/uuid + x-oapi-codegen-extra-tags: + db: team_id + json: team_id + x-go-type-skip-optional-pointer: true + created_at: + $ref: ./common/core.yml#/components/schemas/time + updated_at: + $ref: ./common/core.yml#/components/schemas/time + deleted_at: + $ref: ./common/core.yml#/components/schemas/nullTime + teamsOrganizationsMappingPage: + properties: + page: + type: ./common/core.yml#/components/schemas/number + page_size: + type: ./common/core.yml#/components/schemas/number + total_count: + type: ./common/core.yml#/components/schemas/number + teams_organizations_mapping: + type: array + items: + $ref: '#/components/schemas/teamsOrganizationsMapping' + usersOrganizationsMapping: + properties: + ID: + $ref: ./common/core.yml#/components/schemas/general_id + user_id: + type: string + format: uuid + x-go-type: uuid.UUID + x-go-type-import: + path: github.com/gofrs/uuid + x-oapi-codegen-extra-tags: + db: user_id + json: user_id + x-go-type-skip-optional-pointer: true + organization_id: + type: string + format: uuid + x-go-type: uuid.UUID + x-go-type-import: + path: github.com/gofrs/uuid + x-oapi-codegen-extra-tags: + db: organization_id + json: organization_id + x-go-type-skip-optional-pointer: true + role_id: + type: string + format: uuid + x-go-type: uuid.UUID + x-go-type-import: + path: github.com/gofrs/uuid + x-oapi-codegen-extra-tags: + db: role_id + json: role_id + created_at: + $ref: ./common/core.yml#/components/schemas/time + updated_at: + $ref: ./common/core.yml#/components/schemas/time + deleted_at: + $ref: ./common/core.yml#/components/schemas/nullTime + requestBodies: + organizationPayload: + description: Body for creating organization + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/organizationPayload' \ No newline at end of file From e83fb8b383890f60909fb0fbb12710256ed7040e Mon Sep 17 00:00:00 2001 From: Yash Sharma Date: Fri, 24 Jan 2025 03:35:51 +0530 Subject: [PATCH 2/2] Generate structs Signed-off-by: Yash Sharma --- models/v1beta1/organization.go | 132 ++++++++++++++++++++ schemas/constructs/openapi/organization.yml | 14 +-- scripts/config.yml | 6 +- 3 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 models/v1beta1/organization.go diff --git a/models/v1beta1/organization.go b/models/v1beta1/organization.go new file mode 100644 index 0000000000..829b26a832 --- /dev/null +++ b/models/v1beta1/organization.go @@ -0,0 +1,132 @@ +// Package organization provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.4.1 DO NOT EDIT. +package organization + +import ( + "github.com/gofrs/uuid" + externalRef1 "github.com/meshery/schemas/models/core" +) + +// AvailableOrganization defines model for availableOrganization. +type AvailableOrganization struct { + ID externalRef1.GeneralId `db:"id" json:"id"` + Country externalRef1.Text `json:"country,omitempty"` + CreatedAt externalRef1.Time `json:"created_at,omitempty"` + + // DeletedAt SQL null Timestamp to handle null values of time. + DeletedAt externalRef1.NullTime `json:"deleted_at,omitempty"` + Description externalRef1.Text `json:"description,omitempty"` + Metadata *OrganizationMetadata `json:"metadata,omitempty"` + Name externalRef1.Text `json:"name,omitempty"` + Owner externalRef1.Text `json:"owner,omitempty"` + Region externalRef1.Text `json:"region,omitempty"` + UpdatedAt externalRef1.Time `json:"updated_at,omitempty"` +} + +// Organization defines model for organization. +type Organization struct { + ID externalRef1.GeneralId `db:"id" json:"id"` + Country externalRef1.Text `json:"country,omitempty"` + CreatedAt externalRef1.Time `json:"created_at,omitempty"` + + // DeletedAt SQL null Timestamp to handle null values of time. + DeletedAt externalRef1.NullTime `json:"deleted_at,omitempty"` + Metadata *OrganizationMetadata `json:"metadata,omitempty"` + Name externalRef1.Text `json:"name"` + Owner uuid.UUID `db:"owner" json:"owner"` + Region externalRef1.Text `json:"region,omitempty"` + UpdatedAt externalRef1.Time `json:"updated_at,omitempty"` +} + +// OrganizationMetadata defines model for organizationMetadata. +type OrganizationMetadata struct { + Preferences *OrganizationPreferences `json:"preferences,omitempty"` +} + +// OrganizationPayload defines model for organizationPayload. +type OrganizationPayload struct { + Country externalRef1.Text `json:"country,omitempty"` + Description externalRef1.Text `json:"description,omitempty"` + Name externalRef1.Text `json:"name,omitempty"` + NotifyOrgUpdate *bool `json:"notify_org_update,omitempty"` + Preferences *OrganizationPreferences `json:"preferences,omitempty"` + Region externalRef1.Text `json:"region,omitempty"` +} + +// OrganizationPreferences defines model for organizationPreferences. +type OrganizationPreferences struct { + Dashboard *struct { + Layout *map[string]map[string]interface{} `json:"layout,omitempty"` + } `json:"dashboard,omitempty"` + Theme *struct { + Logo *struct { + // DesktopView Contains the location of the custom desktop view SVG. + DesktopView *string `json:"desktop_view,omitempty"` + + // MobileView Contains the location of the custom mobile view SVG. + MobileView *string `json:"mobile_view,omitempty"` + } `json:"logo,omitempty"` + + // ThemeId ID for the theme to load for the currently selected organization + ThemeId *string `json:"theme_id,omitempty"` + } `json:"theme,omitempty"` +} + +// OrganizationWithRoles defines model for organizationWithRoles. +type OrganizationWithRoles struct { + ID externalRef1.GeneralId `db:"id" json:"id"` + Country externalRef1.Text `json:"country,omitempty"` + CreatedAt externalRef1.Time `json:"created_at,omitempty"` + + // DeletedAt SQL null Timestamp to handle null values of time. + DeletedAt externalRef1.NullTime `json:"deleted_at,omitempty"` + Description externalRef1.Text `json:"description,omitempty"` + Metadata *OrganizationMetadata `json:"metadata,omitempty"` + Name externalRef1.Text `json:"name,omitempty"` + Owner uuid.UUID `db:"owner" json:"owner"` + Region externalRef1.Text `json:"region,omitempty"` + RoleNames externalRef1.RoleNames `json:"role_names,omitempty"` + UpdatedAt externalRef1.Time `json:"updated_at,omitempty"` +} + +// OrganizationsPage defines model for organizationsPage. +type OrganizationsPage struct { + Organizations *[]AvailableOrganization `json:"organizations,omitempty"` + Page externalRef1.Number `json:"page,omitempty"` + PageSize externalRef1.Number `json:"page_size,omitempty"` + TotalCount externalRef1.Number `json:"total_count,omitempty"` +} + +// TeamsOrganizationsMapping defines model for teamsOrganizationsMapping. +type TeamsOrganizationsMapping struct { + ID externalRef1.GeneralId `db:"id" json:"id"` + CreatedAt externalRef1.Time `json:"created_at,omitempty"` + + // DeletedAt SQL null Timestamp to handle null values of time. + DeletedAt externalRef1.NullTime `json:"deleted_at,omitempty"` + OrgId uuid.UUID `db:"org_id" json:"org_id"` + TeamId uuid.UUID `db:"team_id" json:"team_id"` + UpdatedAt externalRef1.Time `json:"updated_at,omitempty"` +} + +// TeamsOrganizationsMappingPage defines model for teamsOrganizationsMappingPage. +type TeamsOrganizationsMappingPage struct { + Page externalRef1.Number `json:"page,omitempty"` + PageSize externalRef1.Number `json:"page_size,omitempty"` + TeamsOrganizationsMapping *[]TeamsOrganizationsMapping `json:"teams_organizations_mapping,omitempty"` + TotalCount externalRef1.Number `json:"total_count,omitempty"` +} + +// UsersOrganizationsMapping defines model for usersOrganizationsMapping. +type UsersOrganizationsMapping struct { + ID externalRef1.GeneralId `db:"id" json:"id"` + CreatedAt externalRef1.Time `json:"created_at,omitempty"` + + // DeletedAt SQL null Timestamp to handle null values of time. + DeletedAt externalRef1.NullTime `json:"deleted_at,omitempty"` + OrganizationId uuid.UUID `db:"organization_id" json:"organization_id"` + RoleId *uuid.UUID `db:"role_id" json:"role_id"` + UpdatedAt externalRef1.Time `json:"updated_at,omitempty"` + UserId uuid.UUID `db:"user_id" json:"user_id"` +} diff --git a/schemas/constructs/openapi/organization.yml b/schemas/constructs/openapi/organization.yml index 5748db671c..498da2e670 100644 --- a/schemas/constructs/openapi/organization.yml +++ b/schemas/constructs/openapi/organization.yml @@ -56,7 +56,7 @@ components: deleted_at: $ref: ./common/core.yml#/components/schemas/nullTime role_names: - $ref: '#/components/schemas/roleNames' + $ref: ./common/core.yml#/components/schemas/roleNames availableOrganization: type: object properties: @@ -143,11 +143,11 @@ components: organizationsPage: properties: page: - type: ./common/core.yml#/components/schemas/number + $ref: ./common/core.yml#/components/schemas/number page_size: - type: ./common/core.yml#/components/schemas/number + $ref: ./common/core.yml#/components/schemas/number total_count: - type: ./common/core.yml#/components/schemas/number + $ref: ./common/core.yml#/components/schemas/number organizations: type: array items: @@ -199,11 +199,11 @@ components: teamsOrganizationsMappingPage: properties: page: - type: ./common/core.yml#/components/schemas/number + $ref: ./common/core.yml#/components/schemas/number page_size: - type: ./common/core.yml#/components/schemas/number + $ref: ./common/core.yml#/components/schemas/number total_count: - type: ./common/core.yml#/components/schemas/number + $ref: ./common/core.yml#/components/schemas/number teams_organizations_mapping: type: array items: diff --git a/scripts/config.yml b/scripts/config.yml index 0397ef9142..4ba202573a 100644 --- a/scripts/config.yml +++ b/scripts/config.yml @@ -1,5 +1,5 @@ # yaml-language-server: $schema=https://raw.githubusercontent.com/deepmap/oapi-codegen/HEAD/configuration-schema.json -package: relationship +package: organization # Update the "output" and "include-tags" based on the resource for which code generation needs to be invoked. generate: @@ -13,10 +13,10 @@ import-mapping: "../v1beta1/component.json": "github.com/meshery/schemas/models/v1beta1/model" "../v1alpha1/capability.json": "github.com/meshery/schemas/models/v1alpha1/capability" -output: models/v1alpha3/relationship/relationship.go +output: models/v1beta1/organization.go output-options: # name-normalizer: ToCamelCaseWithInitialisms skip-prune: true include-tags: - - patterns + - organizations