Skip to content

Commit

Permalink
[KeyVault] - Regenerate from 7.2 stable swagger (#14964)
Browse files Browse the repository at this point in the history
This PR includes regenerated code from the stable 7.2 swagger. Up until now it was in preview, but now that it's 
stable we're regenerating (and expected no meaningful changes).

But there were meaningful changes! Recently our code generator started emitting `null` based on the x-nullable spec
which unfortunately expanded CertificateOperation.error and ErrorModel.innerError to be `ErrorModel | undefined | **null**`
Since this data is going from server to client we can only narrow it, we can't expand it without a breaking change. This is 
made worse because we re-exported ErrorModel as-is in 4.1. 

I looked into it and realized that this is done for historical reasons and not semantically meaningful 
see: Azure/azure-rest-api-specs#10262 (comment).

So I am deprecating `ErrorModel` since we should use the `CertificateOperationError` type anyway, ensuring that the 
existing ErrorModel does not change, and applying the transformation from null to undefined in the convenience layer to 
keep the API the same.
  • Loading branch information
maorleger authored Apr 21, 2021
1 parent f286913 commit e91002c
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 40 deletions.
4 changes: 2 additions & 2 deletions sdk/keyvault/keyvault-admin/swagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ generate-metadata: false
add-credentials: false
license-header: MICROSOFT_MIT_NO_VERSION
input-file:
- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/f7879713cbd89efb2c68c6b6f2566b49db97d832/specification/keyvault/data-plane/Microsoft.KeyVault/preview/7.2-preview/rbac.json
- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/f7879713cbd89efb2c68c6b6f2566b49db97d832/specification/keyvault/data-plane/Microsoft.KeyVault/preview/7.2-preview/backuprestore.json
- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/1e2c9f3ec93078da8078389941531359e274f32a/specification/keyvault/data-plane/Microsoft.KeyVault/stable/7.2/rbac.json
- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/1e2c9f3ec93078da8078389941531359e274f32a/specification/keyvault/data-plane/Microsoft.KeyVault/stable/7.2/backuprestore.json
output-folder: ../
source-code-folder-path: ./src/generated
```
Expand Down
1 change: 1 addition & 0 deletions sdk/keyvault/keyvault-certificates/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 4.2.0-beta.4 (Unreleased)

- Marked `ErrorModel` as deprecated. It was erronously exported publicly in 4.1 and should not be used. Please change the type to use `CertificateOperationError` instead.

## 4.2.0-beta.3 (2021-04-06)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export type DeleteIssuerOptions = coreHttp.OperationOptions;
// @public
export type DeletionRecoveryLevel = string;

// @public
// @public @deprecated
export interface ErrorModel {
readonly code?: string;
readonly innerError?: ErrorModel;
Expand Down
22 changes: 22 additions & 0 deletions sdk/keyvault/keyvault-certificates/src/certificatesModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ export interface CertificateOperationError {
readonly innerError?: CertificateOperationError;
}

/**
* The key vault server error model.
* @deprecated - Please use {@link CertificateOperationError} instead.
*/
// This was re-exported as-is from generated code in 4.1; however, we should only be using `CertificateOperationError`.
export interface ErrorModel {
/**
* The error code.
* **NOTE: This property will not be serialized. It can only be populated by the server.**
*/
readonly code?: string;
/**
* The error message.
* **NOTE: This property will not be serialized. It can only be populated by the server.**
*/
readonly message?: string;
/**
* **NOTE: This property will not be serialized. It can only be populated by the server.**
*/
readonly innerError?: ErrorModel;
}

/**
* A certificate operation is returned in case of asynchronous requests.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as Mappers from "./models/mappers";
import { KeyVaultClientContext } from "./keyVaultClientContext";
import {
KeyVaultClientOptionalParams,
ApiVersion72Preview,
ApiVersion72,
KeyVaultClientGetCertificatesOptionalParams,
KeyVaultClientGetCertificatesResponse,
KeyVaultClientDeleteCertificateResponse,
Expand Down Expand Up @@ -69,7 +69,7 @@ export class KeyVaultClient extends KeyVaultClientContext {
* @param options The parameter options
*/
constructor(
apiVersion: ApiVersion72Preview,
apiVersion: ApiVersion72,
options?: KeyVaultClientOptionalParams
) {
super(apiVersion, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
*/

import * as coreHttp from "@azure/core-http";
import { ApiVersion72Preview, KeyVaultClientOptionalParams } from "./models";
import { ApiVersion72, KeyVaultClientOptionalParams } from "./models";

const packageName = "@azure/keyvault-certificates";
export const packageVersion = "4.2.0-beta.4";

/** @hidden */
export class KeyVaultClientContext extends coreHttp.ServiceClient {
apiVersion: ApiVersion72Preview;
apiVersion: ApiVersion72;

/**
* Initializes a new instance of the KeyVaultClientContext class.
* @param apiVersion Api Version
* @param options The parameter options
*/
constructor(
apiVersion: ApiVersion72Preview,
apiVersion: ApiVersion72,
options?: KeyVaultClientOptionalParams
) {
if (apiVersion === undefined) {
Expand Down
24 changes: 12 additions & 12 deletions sdk/keyvault/keyvault-certificates/src/generated/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface KeyVaultError {
* The key vault server error.
* NOTE: This property will not be serialized. It can only be populated by the server.
*/
readonly error?: ErrorModel;
readonly error?: ErrorModel | null;
}

/** The key vault server error. */
Expand All @@ -79,7 +79,7 @@ export interface ErrorModel {
* The key vault server error.
* NOTE: This property will not be serialized. It can only be populated by the server.
*/
readonly innerError?: ErrorModel;
readonly innerError?: ErrorModel | null;
}

/** A certificate bundle consists of a certificate (X509) plus its attributes. */
Expand Down Expand Up @@ -142,7 +142,7 @@ export interface CertificatePolicy {

/** Properties of the key pair backing a certificate. */
export interface KeyProperties {
/** Indicates if the private key can be exported. */
/** Not supported in this version. Indicates if the private key can be exported. */
exportable?: boolean;
/** The type of key pair to be used for the certificate. */
keyType?: JsonWebKeyType;
Expand Down Expand Up @@ -372,7 +372,7 @@ export interface CertificateOperation {
/** The status details of the certificate operation. */
statusDetails?: string;
/** Error encountered, if any, during the certificate operation. */
error?: ErrorModel;
error?: ErrorModel | null;
/** Location which contains the result of the certificate operation. */
target?: string;
/** Identifier for the certificate operation. */
Expand Down Expand Up @@ -503,20 +503,20 @@ export type DeletedCertificateBundle = CertificateBundle & {
readonly deletedDate?: Date;
};

/** Known values of {@link ApiVersion72Preview} that the service accepts. */
export const enum KnownApiVersion72Preview {
/** Api Version '7.2-preview' */
Seven2Preview = "7.2-preview"
/** Known values of {@link ApiVersion72} that the service accepts. */
export const enum KnownApiVersion72 {
/** Api Version '7.2' */
Seven2 = "7.2"
}

/**
* Defines values for ApiVersion72Preview. \
* {@link KnownApiVersion72Preview} can be used interchangeably with ApiVersion72Preview,
* Defines values for ApiVersion72. \
* {@link KnownApiVersion72} can be used interchangeably with ApiVersion72,
* this enum contains the known values that the service supports.
* ### Know values supported by the service
* **7.2-preview**: Api Version '7.2-preview'
* **7.2**: Api Version '7.2'
*/
export type ApiVersion72Preview = string;
export type ApiVersion72 = string;

/** Known values of {@link DeletionRecoveryLevel} that the service accepts. */
export const enum KnownDeletionRecoveryLevel {
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault-certificates/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
CertificateTags,
ImportCertificateOptions,
ListPropertiesOfCertificatesOptions,
ErrorModel,
ListPropertiesOfCertificateVersionsOptions,
ListPropertiesOfIssuersOptions,
ListDeletedCertificatesOptions,
Expand Down Expand Up @@ -89,7 +90,6 @@ import {
KeyVaultClientSetCertificateIssuerOptionalParams,
BackupCertificateResult,
KeyVaultClientGetDeletedCertificatesOptionalParams,
ErrorModel,
IssuerParameters,
IssuerCredentials,
IssuerAttributes,
Expand Down
21 changes: 18 additions & 3 deletions sdk/keyvault/keyvault-certificates/src/transformations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
KeyVaultCertificate,
KeyVaultCertificateWithPolicy,
SubjectAlternativeNames,
CertificateContact
CertificateContact,
CertificateOperationError
} from "./certificatesModels";
import {
CertificateAttributes,
Expand All @@ -26,7 +27,8 @@ import {
X509CertificateProperties,
CertificateOperation as CoreCertificateOperation,
Contacts as CoreContacts,
JsonWebKeyType as CertificateKeyType
JsonWebKeyType as CertificateKeyType,
ErrorModel
} from "./generated/models";
import { parseKeyVaultCertificateId } from "./identifier";

Expand Down Expand Up @@ -307,6 +309,19 @@ export function getDeletedCertificateFromItem(item: DeletedCertificateItem): Del
};
}

function getCertificateOperationErrorFromErrorModel(
error?: ErrorModel | null
): CertificateOperationError | undefined {
if (error) {
return {
code: error.code,
innerError: getCertificateOperationErrorFromErrorModel(error.innerError),
message: error.message
};
}
return undefined;
}

export function getCertificateOperationFromCoreOperation(
certificateName: string,
vaultUrl: string,
Expand All @@ -323,7 +338,7 @@ export function getCertificateOperationFromCoreOperation(
? operation.issuerParameters.certificateType
: undefined,
csr: operation.csr,
error: operation.error,
error: getCertificateOperationErrorFromErrorModel(operation.error),
id: operation.id,
requestId: operation.requestId,
status: operation.status,
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault-certificates/swagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ azure-arm: false
generate-metadata: false
add-credentials: false
license-header: MICROSOFT_MIT_NO_VERSION
input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/f9caf92527ccff06c5b66380e6f2b4f50f5e82b3/specification/keyvault/data-plane/Microsoft.KeyVault/preview/7.2-preview/certificates.json
input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/1e2c9f3ec93078da8078389941531359e274f32a/specification/keyvault/data-plane/Microsoft.KeyVault/stable/7.2/certificates.json
output-folder: ../
source-code-folder-path: ./src/generated
hide-clients: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { assert } from "chai";
import { CertificateOperation as CoreCertificateOperation } from "../../src/generated/models";
import { getCertificateOperationFromCoreOperation } from "../../src/transformations";

describe("transformations", function() {
describe("getCertificateOperationFromCoreOperation", function() {
it("transforms null error to undefined", function() {
const input: CoreCertificateOperation = {
error: null
};

assert.isUndefined(getCertificateOperationFromCoreOperation("", "", input).error);
});

it("transforms null inner error to undefined", function() {
const input: CoreCertificateOperation = {
error: {
innerError: null
}
};

const output = getCertificateOperationFromCoreOperation("", "", input);
assert.isDefined(output.error);
assert.isUndefined(output.error!.innerError);
});

it("transforms errors correctly when present", function() {
const input: CoreCertificateOperation = {
error: {
code: "outer error",
message: "The outer error message",
innerError: {
code: "inner error",
innerError: undefined,
message: "The inner error message"
}
}
};

const output = getCertificateOperationFromCoreOperation("", "", input);
assert.deepNestedInclude(output, input);
});
});
});
4 changes: 2 additions & 2 deletions sdk/keyvault/keyvault-keys/src/generated/keyVaultClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as Mappers from "./models/mappers";
import { KeyVaultClientContext } from "./keyVaultClientContext";
import {
KeyVaultClientOptionalParams,
ApiVersion72Preview,
ApiVersion72,
JsonWebKeyType,
KeyVaultClientCreateKeyOptionalParams,
KeyVaultClientCreateKeyResponse,
Expand Down Expand Up @@ -61,7 +61,7 @@ export class KeyVaultClient extends KeyVaultClientContext {
* @param options The parameter options
*/
constructor(
apiVersion: ApiVersion72Preview,
apiVersion: ApiVersion72,
options?: KeyVaultClientOptionalParams
) {
super(apiVersion, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
*/

import * as coreHttp from "@azure/core-http";
import { ApiVersion72Preview, KeyVaultClientOptionalParams } from "./models";
import { ApiVersion72, KeyVaultClientOptionalParams } from "./models";

const packageName = "@azure/keyvault-keys";
export const packageVersion = "4.2.0-beta.6";

/** @hidden */
export class KeyVaultClientContext extends coreHttp.ServiceClient {
apiVersion: ApiVersion72Preview;
apiVersion: ApiVersion72;

/**
* Initializes a new instance of the KeyVaultClientContext class.
* @param apiVersion Api Version
* @param options The parameter options
*/
constructor(
apiVersion: ApiVersion72Preview,
apiVersion: ApiVersion72,
options?: KeyVaultClientOptionalParams
) {
if (apiVersion === undefined) {
Expand Down
18 changes: 10 additions & 8 deletions sdk/keyvault/keyvault-keys/src/generated/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ export interface DeletedKeyListResult {

/** Properties of the key pair backing a certificate. */
export interface KeyProperties {
/** Not supported in this version. Indicates if the private key can be exported. */
exportable?: boolean;
/** The type of key pair to be used for the certificate. */
keyType?: JsonWebKeyType;
/** The key size in bits. For example: 2048, 3072, or 4096 for RSA. */
Expand Down Expand Up @@ -317,20 +319,20 @@ export type DeletedKeyItem = KeyItem & {
readonly deletedDate?: Date;
};

/** Known values of {@link ApiVersion72Preview} that the service accepts. */
export const enum KnownApiVersion72Preview {
/** Api Version '7.2-preview' */
Seven2Preview = "7.2-preview"
/** Known values of {@link ApiVersion72} that the service accepts. */
export const enum KnownApiVersion72 {
/** Api Version '7.2' */
Seven2 = "7.2"
}

/**
* Defines values for ApiVersion72Preview. \
* {@link KnownApiVersion72Preview} can be used interchangeably with ApiVersion72Preview,
* Defines values for ApiVersion72. \
* {@link KnownApiVersion72} can be used interchangeably with ApiVersion72,
* this enum contains the known values that the service supports.
* ### Know values supported by the service
* **7.2-preview**: Api Version '7.2-preview'
* **7.2**: Api Version '7.2'
*/
export type ApiVersion72Preview = string;
export type ApiVersion72 = string;

/** Known values of {@link JsonWebKeyType} that the service accepts. */
export const enum KnownJsonWebKeyType {
Expand Down
6 changes: 6 additions & 0 deletions sdk/keyvault/keyvault-keys/src/generated/models/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,12 @@ export const KeyProperties: coreHttp.CompositeMapper = {
name: "Composite",
className: "KeyProperties",
modelProperties: {
exportable: {
serializedName: "exportable",
type: {
name: "Boolean"
}
},
keyType: {
serializedName: "kty",
type: {
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault-keys/swagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ azure-arm: false
generate-metadata: false
add-credentials: false
license-header: MICROSOFT_MIT_NO_VERSION
input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/612f78afd05911d0e1e82ba72b41781f655dbffb/specification/keyvault/data-plane/Microsoft.KeyVault/preview/7.2-preview/keys.json
input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/1e2c9f3ec93078da8078389941531359e274f32a/specification/keyvault/data-plane/Microsoft.KeyVault/stable/7.2/keys.json
output-folder: ../
source-code-folder-path: ./src/generated
disable-async-iterators: true
Expand Down
Loading

0 comments on commit e91002c

Please sign in to comment.