Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa pagina si applica ad Apigee e Apigee hybrid.
L'hub API fornisce un linter Spectral (strumento di convalida) integrato che convalida la specifica OpenAPI della tua API. Poco dopo aver aggiunto una specifica OpenAPI alla versione dell'API, lo strumento di convalida (abilitato per impostazione predefinita) convalida la specifica e segnala i risultati nella console Google Cloud.
Disattivare la convalida delle specifiche
Per impostazione predefinita, il lint è attivo. Per disattivare il lint,
nella console Google Cloud, vai alla pagina Hub API > Impostazioni > Azioni e poi nella sezione Linting,
disattiva l'opzione Linting.
Guida di stile
Una guida di stile è un insieme di regole in base alle quali l'hub API convalida una specifica OpenAPI.
L'hub API utilizza una guida di stile predefinita per convalidare le specifiche OpenAPI. Per le regole della guida di stile predefinite, consulta Regole OpenAPI.
Carica una nuova guida di stile
Console
Per caricare una nuova guida di stile:
Crea un nuovo stile estendendo la guida di stile predefinita. Per ulteriori informazioni, vedi Creare un insieme di regole.
Nella console Google Cloud, vai alla pagina Hub API > Impostazioni > Azioni.
Nella sezione Linting, fai clic su Carica nuovo documento di stile.
Carica il nuovo documento di stile (creato nel passaggio 1), quindi fai clic su Salva.
API REST
Per caricare una nuova guida di stile per il linting, invia una richiesta PATCH
alla seguente API:
Per scaricare la guida di stile predefinita utilizzata dall'hub API per il linting,
segui questi passaggi:
Nella console Google Cloud, vai alla pagina Hub API > Impostazioni > Azioni.
Nella sezione Linting, fai clic su Scarica il documento di stile predefinito. In questo modo, il documento di stile predefinito viene scaricato sul tuo sistema locale.
Scarica la guida di stile più recente
Console
Per scaricare la guida di stile attualmente utilizzata da API Hub per il linting,
segui questi passaggi:
Nella console Google Cloud, vai alla pagina Hub API > Impostazioni > Azioni.
Nella sezione Linting, fai clic su Scarica l'ultimo documento di stile. In questo modo
il documento di stile predefinito viene scaricato sul tuo sistema locale.
API REST
Per scaricare la guida allo stile attualmente utilizzata da API Hub per il linting, invia una richiesta GET
alla seguente API:
Le guide di stile non possono contenere URL. Assicurati di non includere URL nella proprietà extends del tuo insieme di regole quando crei e carichi una guida di stile. Ad esempio, la seguente costruzione della proprietà potrebbe causare il fallimento del caricamento:
extends: [spectral:oas", "https://mystyle.com/"].
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-08 UTC."],[[["\u003cp\u003eAPI hub features an in-built Spectral linter that validates OpenAPI specifications, with linting enabled by default, and the terms \u003ccode\u003elinting\u003c/code\u003e and \u003ccode\u003evalidating\u003c/code\u003e used interchangeably.\u003c/p\u003e\n"],["\u003cp\u003eUsers can disable specification validation in the Google Cloud console under API hub settings.\u003c/p\u003e\n"],["\u003cp\u003eAPI hub uses a default style guide for OpenAPI validation, and users can create and upload custom style guides by extending the default one.\u003c/p\u003e\n"],["\u003cp\u003eThe default and the latest style guides can be downloaded from the Google Cloud console or through REST API calls.\u003c/p\u003e\n"],["\u003cp\u003eStyle guides uploaded are restricted to not include URLs in the \u003ccode\u003eextends\u003c/code\u003e property of the ruleset.\u003c/p\u003e\n"]]],[],null,["*This page\napplies to **Apigee** and **Apigee hybrid**.*\n|\n| **Preview\n| --- Apigee API hub linting feature**\n|\n|\n| This feature is\n|\n| subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section of the\n| [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nAPI hub provides an in-built [Spectral linter](https://stoplight.io/open-source/spectral) (validator)\nwhich validates your API's OpenAPI specification. Soon after you add an OpenAPI specification to your API version,\nthe validator (which is enabled by default) validates the specification, and reports the findings in the Google Cloud console.\n| **Note:** In this topic, the terms `linting` and `validating` are used interchangeably. Both these terms mean the same.\n\nDisable specification validation\n\nBy default, the linter is enabled. To disable the linter,\nin the Google Cloud console, go to the **API hub \\\u003e Settings \\\u003e Actions** page, and then in the **Linting** section,\ndisable the **Linting** option.\n\nStyle guide\n\nA style guide is a set of rules against which API hub validates an OpenAPI specification.\nAPI hub uses a default style guide for validating the OpenAPI specifications. For\nthe default style guide rules, see [OpenAPI Rules](https://meta.stoplight.io/docs/spectral/4dec24461f3af-open-api-rules).\n| **Note:**To add your own custom rules, you must create a new style guide that extends the default style guide. After adding your custom rules in the new style guide, you must upload the new style guide in API hub.\n\nUpload a new style guide \n\nConsole\n\nTo upload a new style guide, do the following steps:\n\n1. Create a new style by extending the default style guide. For more information, see [Create a ruleset](https://meta.stoplight.io/docs/spectral/01baf06bdd05a-create-a-ruleset).\n2. In the Google Cloud console, go to the **API hub \\\u003e Settings \\\u003e Actions** page.\n\n3. In the **Linting** section, click **Upload new style document**.\n4. Upload the new style document (created in step 1), and then click **Save**.\n\nREST API\n\nTo upload a new style guide for linting, issue a `PATCH` request\nto the following API:\n`https://apihub.googleapis.com/v1/projects/`\u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e`/locations/`\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`/plugins/standard-linter/styleGuide?update_mask=contents`\n\nFor more information about the API, see [UpdateStyleGuide](/apigee/docs/reference/apis/apihub/rest/v1/projects.locations.plugins/updateStyleGuide).\n\nThe following example shows the API call to upload a style guide. \n\n```\ncurl \\\n-H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n-H \"Content-Type: application/json\" \\\n-d '{\"name\":\"projects/test-project-1/locations/us-central1/plugins/standard-linter/styleGuide\",\n\"contents\":{ \"contents\": \"ZXh0ZW5kczogWyJzcGVjdHJhbDpvYXMiXQo=\",\n \"mimeType\": \"text/yaml\"}}' \\ \n-X PATCH \\\nhttps://apihub.googleapis.com/v1/projects/test-project-1/locations/us-central1/plugins/standard-linter/styleGuide?update_mask=contents \n```\n\nDownload the default style guide\n\nTo download the default style guide used by API hub for linting,\ndo the following steps:\n\n1. In the Google Cloud console, go to the **API hub \\\u003e Settings \\\u003e Actions** page.\n\n2. In the **Linting** section, click **Download default style document**. This downloads the default style document to your local system.\n\nDownload the latest style guide \n\nConsole\n\nTo download the style guide that is currently used by API hub for linting,\ndo the following steps:\n\n1. In the Google Cloud console, go to the **API hub \\\u003e Settings \\\u003e Actions** page.\n\n2. In the **Linting** section, click **Download latest style document**. This downloads the default style document to your local system.\n\nREST API\n\nTo download the style guide that is currently used by API hub for linting, issue a `GET` request\nto the following API:\n`https://apihub.googleapis.com/v1/projects/`\u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e`/locations/`\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`/plugins/standard-linter/styleGuide:contents`\n\nFor more information about the API, see [GetStyleGuide](/apigee/docs/reference/apis/apihub/rest/v1/projects.locations.plugins/getStyleGuide).\n\nThe following example shows the API call to download the current style guide. \n\n```\ncurl -X \\\nGET -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n https://apihub.googleapis.com/v1/projects/test-project-1/locations/us-central1/plugins/standard-linter/styleGuide:contents\n```\n\nLimitations\n\nThe following limitations apply when creating and uploading custom style guides:\n\n- **No URLs in `extends` property** : Style guides can't contain URLs. Ensure that you don't include any URLs in the `extends` property of your ruleset when creating and uploading a style guide. For example, the following property construction might cause the upload to fail: `extends: [spectral:oas\", \"https://mystyle.com/\"]`.\n- **`functionsDir` not allowed** : The `functionsDir` property is not allowed in custom style guides. Spectral style guides with JavaScript will not be executed by API hub during the linting process.\n\n As a workaround, if you require the use of a custom style guide with JavaScript functions, perform the following steps:\n 1. Run [Spectral](https://stoplight.io/open-source/spectral) outside of API hub using your custom style guide.\n 2. Update the linting results in the `Lint` attribute of the specification file in API hub."]]