Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add operations tag to esr xml and operationId to yaml #6013

Merged
merged 4 commits into from
Jan 18, 2025

Conversation

CristiCanizales
Copy link
Contributor

@CristiCanizales CristiCanizales commented Jan 17, 2025

What does this PR do?

  • Adds Operations Tag to External Service Registration XML and operationId to yaml within schema tag

What issues does this PR fix or reference?

@W-17626169@

ESR

<?xml version="1.0" encoding="UTF-8"?>
<ExternalServiceRegistration xmlns="http://soap.sforce.com/2006/04/metadata">
  <description>Property API for managing properties</description>
  <label>PropertyAPI</label>
  <schema>openapi: 3.0.0
info:
  title: Property API
  version: &apos;1.0.0&apos;
  description: Property API for managing properties
paths:
  /PropertyAPI/getPropertyById:
    get:
      summary: Get property by ID
      operationId: getPropertyById
      responses:
        &apos;200&apos;:
          description: Property found
          content:
            application/json:
              schema:
                $ref: &apos;#/components/schemas/Property&apos;
  /PropertyAPI/createProperty:
    post:
      summary: Create property
      operationId: createProperty
      parameters:
        - name: searchKey
          in: query
          required: true
          schema:
            type: string
        - name: maxPrice
          in: query
          required: true
          schema:
            type: integer
        - name: minBedrooms
          in: query
          required: true
          schema:
            type: integer
        - name: minBathrooms
          in: query
          required: true
          schema:
            type: integer
      responses:
        &apos;200&apos;:
          description: Property created
          content:
            application/json:
              schema:
                $ref: &apos;#/components/schemas/Property&apos;
components:
  schemas:
    Property:
      type: object
      properties:
        Id:
          type: string
        Address:
          type: string
        Price:
          type: integer
        Bedrooms:
          type: integer
        Bathrooms:
          type: integer
</schema>
  <schemaType>OpenApi3</schemaType>
  <schemaUploadFileExtension>yaml</schemaUploadFileExtension>
  <schemaUploadFileName>propertyapi_openapi</schemaUploadFileName>
  <status>Complete</status>
  <systemVersion>3</systemVersion>
  <operations>
    <ExternalServiceOperation>
      <name>getPropertyById</name>
      <active>true</active>
    </ExternalServiceOperation>
    <ExternalServiceOperation>
      <name>createProperty</name>
      <active>true</active>
    </ExternalServiceOperation>
  </operations>
  <registrationProvider>PropertyAPI</registrationProvider>
  <registrationProviderType>Custom</registrationProviderType>
  <namedCredentialReference>Guariqueteo1</namedCredentialReference>
</ExternalServiceRegistration>

@CristiCanizales CristiCanizales self-assigned this Jan 17, 2025
@CristiCanizales CristiCanizales requested a review from a team as a code owner January 17, 2025 22:12
@CristiCanizales CristiCanizales requested review from klewis-sfdc, peternhale and mingxuanzhangsfdx and removed request for klewis-sfdc January 17, 2025 22:12
Copy link
Member

@mingxuanzhangsfdx mingxuanzhangsfdx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with a class

@RestResource(urlMapping='/property/*')
global with sharing class PropertyAPI implements PropertyAPIInterface {
    @HttpGet
    global static String getPropertyById() {
        RestRequest request = RestContext.request;
        // Grab the caseId from the end of the URL
        String propertyId = request.requestURI.substring(
            request.requestURI.lastIndexOf('/')+1);
        return 'hello';
    }

    @HttpPost
    global static String createProperty(String searchKey, Integer maxPrice, Integer minBedrooms, Integer minBathrooms) {
        Property newProperty = new Property();
        return 'world';
    }

    @TestVisible
    private string anotherFunc() {
        return 'hello';
    }
    
    public class Property {
        public String Id;
        public String Address;
        public Integer Price;
        public Integer Bedrooms;
        public Integer Bathrooms;
    }
    
    @TestVisible
    private Integer privateIntegerProperty;

    @AuraEnabled
    public String stringProperty { get; set; }

    @AuraEnabled
    public Decimal decimalProperty { get; set; }

    @TestVisible
    private List<String> privateListProperty;

    @AuraEnabled
    public List<Integer> integerListProperty { get; set; }

    @AuraEnabled
    public Map<String, String> stringMapProperty { get; set; }

    public class PropertyException extends Exception {}
}

and got the result

<?xml version="1.0" encoding="UTF-8"?>
<ExternalServiceRegistration xmlns="http://soap.sforce.com/2006/04/metadata">
  <description>This is an API for managing properties.</description>
  <label>PropertyAPI</label>
  <schema>openapi: 3.0.0
info:
  title: Property API
  version: &apos;1.0.0&apos;
  description: This is an API for managing properties.
paths:
  /PropertyAPI/createProperty:
    post:
      summary: Create a new property
      operationId: createProperty
      requestBody:
        content:
          application/json:
            schema:
              $ref: &apos;#/components/schemas/Property&apos;
      responses:
        &apos;200&apos;:
          description: The newly created property
          content:
            application/json:
              schema:
                $ref: &apos;#/components/schemas/Property&apos;
  /PropertyAPI/getPropertyById:
    get:
      summary: Get a property by ID
      operationId: getPropertyById
      parameters:
        - name: propertyId
          in: path
          required: true
          description: The ID of the property to retrieve
          schema:
            type: string
      responses:
        &apos;200&apos;:
          description: The requested property
          content:
            application/json:
              schema:
                $ref: &apos;#/components/schemas/Property&apos;
components:
  schemas:
    Property:
      type: object
      properties:
        Id:
          type: string
        Address:
          type: string
        Price:
          type: integer
        Bedrooms:
          type: integer
        Bathrooms:
          type: integer
</schema>
  <schemaType>OpenApi3</schemaType>
  <schemaUploadFileExtension>yaml</schemaUploadFileExtension>
  <schemaUploadFileName>propertyapi_openapi</schemaUploadFileName>
  <status>Complete</status>
  <systemVersion>3</systemVersion>
  <operations>
    <ExternalServiceOperation>
      <name>createProperty</name>
      <active>true</active>
    </ExternalServiceOperation>
    <ExternalServiceOperation>
      <name>getPropertyById</name>
      <active>true</active>
    </ExternalServiceOperation>
  </operations>
  <registrationProvider>PropertyAPI</registrationProvider>
  <registrationProviderType>Custom</registrationProviderType>
  <namedCredentialReference>somenamed</namedCredentialReference>
</ExternalServiceRegistration>

which looks good

@CristiCanizales CristiCanizales merged commit e0d4141 into feat/apex-oas Jan 18, 2025
6 checks passed
@CristiCanizales CristiCanizales deleted the cristi/operations branch January 18, 2025 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants