public ConstrainableHeader type(JsonFieldType fieldType) { return (ConstrainableHeader)attributes(type.value(fieldType)); } }
@Override public void document(Operation operation) throws IOException { RestDocumentationContext context = (RestDocumentationContext) operation .getAttributes().get(RestDocumentationContext.class.getName()); WriterResolver writerResolver = (WriterResolver) operation.getAttributes() .get(WriterResolver.class.getName()); try (Writer writer = writerResolver.resolve( operation.getName() + "/" + getSnippetName(), this.file, context)) { Map<String, Object> model = createModel(operation); model.putAll(getAttributes()); TemplateEngine templateEngine = (TemplateEngine) operation.getAttributes() .get(TemplateEngine.class.getName()); writer.append(templateEngine.compileTemplate(getSnippetName()).render(model)); } }
public ConstrainableParameter type(JsonFieldType fieldType) { return (ConstrainableParameter)attributes(type.value(fieldType)); } }
public ConstrainableParameter required() { return (ConstrainableParameter)attributes(constraints.value(REQUIRED)); }
public ConstrainableField optional(Object defaultValue) { super.optional(); String defaultValueText; if(defaultValue == null) { defaultValueText = ""; } else { defaultValueText = JsonUtils.writeValueAsString(defaultValue); } Attributes.Attribute[] attrs = new Attributes.Attribute[] {key("constraints").value(hasText(defaultValueText) ? "Optional (defaults to `" + defaultValueText + "`)" : OPTIONAL)}; return (ConstrainableField)attributes(attrs).optional(); }
public ConstrainableField required() { return (ConstrainableField)attributes(constraints.value(REQUIRED)); }
public SubField(String path, FieldDescriptor subFieldDescriptor) { super(path + "." + subFieldDescriptor.getPath()); type(subFieldDescriptor.getType()); description(subFieldDescriptor.getDescription()); if(subFieldDescriptor.isIgnored()) { ignored(); } List<Attributes.Attribute> attributes = subFieldDescriptor.getAttributes().entrySet().stream().map(e -> key(e.getKey()).value(e.getValue())).collect(Collectors.toList()); attributes(attributes.toArray(new Attributes.Attribute[attributes.size()])); if(subFieldDescriptor.isOptional()) { optional(); } } }
public ConstrainableHeader required() { return (ConstrainableHeader)attributes(constraints.value(REQUIRED)); }
fieldWithPath("description").type(STRING).description(DESCRIPTION_DESC).optional(), fieldWithPath("version").description(VERSION_DESC), fieldWithPath("active").description(ACTIVE_DESC).attributes(key("constraints").value("Optional")), fieldWithPath("config.tokenPolicy.jwtRevocable").type(BOOLEAN).description(JWT_REVOCABLE_DESC).attributes(key("constraints").value("Optional")), fieldWithPath("config.tokenPolicy.refreshTokenUnique").type(BOOLEAN).description(REFRESH_TOKEN_UNIQUE).attributes(key("constraints").value("Optional")), fieldWithPath("config.tokenPolicy.refreshTokenFormat").type(STRING).description(REFRESH_TOKEN_FORMAT).attributes(key("constraints").value("Optional")), fieldWithPath("config.clientSecretPolicy.minLength").type(NUMBER).description(SECRET_POLICY_MIN_LENGTH).attributes(key("constraints").value("Required when `clientSecretPolicy` in the config is not null")), fieldWithPath("config.clientSecretPolicy.maxLength").type(NUMBER).description(SECRET_POLICY_MAX_LENGTH).attributes(key("constraints").value("Required when `clientSecretPolicy` in the config is not null")), fieldWithPath("config.clientSecretPolicy.requireUpperCaseCharacter").type(NUMBER).description(SECRET_POLICY_UPPERCASE).attributes(key("constraints").value("Required when `clientSecretPolicy` in the config is not null")), fieldWithPath("config.clientSecretPolicy.requireLowerCaseCharacter").type(NUMBER).description(SECRET_POLICY_LOWERCASE).attributes(key("constraints").value("Required when `clientSecretPolicy` in the config is not null")), fieldWithPath("config.clientSecretPolicy.requireDigit").type(NUMBER).description(SECRET_POLICY_DIGIT).attributes(key("constraints").value("Required when `clientSecretPolicy` in the config is not null")), fieldWithPath("config.clientSecretPolicy.requireSpecialCharacter").type(NUMBER).description(SECRET_POLICY_SPECIAL_CHAR).attributes(key("constraints").value("Required when `clientSecretPolicy` in the config is not null")), fieldWithPath("config.samlConfig.certificate").type(STRING).description(CERTIFICATE_DESC).attributes(key("constraints").value("Deprecated")), fieldWithPath("config.samlConfig.activeKeyId").optional().type(STRING).description(SAML_ACTIVE_KEY_ID_DESC), fieldWithPath("config.samlConfig.keys.*.certificate").type(STRING).description(CERTIFICATE_DESC), fieldWithPath("config.prompts[].text").description(PROMPTS_TEXT_DESC), fieldWithPath("config.defaultIdentityProvider").type(STRING).description(DEFAULT_IDP_DESC).optional().attributes(key("constraints").value("Optional")), fieldWithPath("config.idpDiscoveryEnabled").description(IDP_DISCOVERY_ENABLED_FLAG), fieldWithPath("config.accountChooserEnabled").description(ACCOUNT_CHOOSER_ENABLED_FLAG),
fieldWithPath("[].description").description(DESCRIPTION_DESC), fieldWithPath("[].version").description(VERSION_DESC), fieldWithPath("[].active").description(ACTIVE_DESC).attributes(key("constraints").value("Optional")), fieldWithPath("[].config.tokenPolicy.refreshTokenValidity").description(REFRESH_TOKEN_VALIDITY_DESC), fieldWithPath("[].config.tokenPolicy.jwtRevocable").type(BOOLEAN).description(JWT_REVOCABLE_DESC), fieldWithPath("[].config.tokenPolicy.refreshTokenUnique").type(BOOLEAN).description(REFRESH_TOKEN_UNIQUE).attributes(key("constraints").value("Optional")), fieldWithPath("[].config.tokenPolicy.refreshTokenFormat").type(STRING).description(REFRESH_TOKEN_FORMAT).attributes(key("constraints").value("Optional")), fieldWithPath("[].config.clientSecretPolicy.minLength").type(NUMBER).description(SECRET_POLICY_MIN_LENGTH).attributes(key("constraints").value("Required when `clientSecretPolicy` in the config is not null")), fieldWithPath("[].config.clientSecretPolicy.maxLength").type(NUMBER).description(SECRET_POLICY_MAX_LENGTH).attributes(key("constraints").value("Required when `clientSecretPolicy` in the config is not null")), fieldWithPath("[].config.clientSecretPolicy.requireUpperCaseCharacter").type(NUMBER).description(SECRET_POLICY_UPPERCASE).attributes(key("constraints").value("Required when `clientSecretPolicy` in the config is not null")), fieldWithPath("[].config.clientSecretPolicy.requireLowerCaseCharacter").type(NUMBER).description(SECRET_POLICY_LOWERCASE).attributes(key("constraints").value("Required when `clientSecretPolicy` in the config is not null")), fieldWithPath("[].config.clientSecretPolicy.requireDigit").type(NUMBER).description(SECRET_POLICY_DIGIT).attributes(key("constraints").value("Required when `clientSecretPolicy` in the config is not null")), fieldWithPath("[].config.clientSecretPolicy.requireSpecialCharacter").type(NUMBER).description(SECRET_POLICY_SPECIAL_CHAR).attributes(key("constraints").value("Required when `clientSecretPolicy` in the config is not null")), fieldWithPath("[]config.samlConfig.disableInResponseToCheck").description(SAML_DISABLE_IN_RESPONSE_TO_DESC).attributes(key("constraints").value("Optional")), fieldWithPath("[].config.samlConfig.assertionSigned").description(ASSERTION_SIGNED_DESC), fieldWithPath("[].config.samlConfig.wantAssertionSigned").description(WANT_ASSERTION_SIGNED_DESC), fieldWithPath("[].config.samlConfig.assertionTimeToLiveSeconds").description(ASSERTION_TIME_TO_LIVE_SECONDS_DESC), fieldWithPath("[].config.samlConfig.entityID").type(STRING).description(ENTITY_ID_DESC), fieldWithPath("[].config.samlConfig.certificate").type(STRING).description(CERTIFICATE_DESC).attributes(key("constraints").value("Deprecated")), fieldWithPath("[].config.branding.companyName").description(BRANDING_COMPANY_NAME_DESC).attributes(key("constraints").value("Optional")), fieldWithPath("[].config.branding.productLogo").description(BRANDING_PRODUCT_LOGO_DESC).attributes(key("constraints").value("Optional")), fieldWithPath("[].config.branding.squareLogo").description(BRANDING_SQUARE_LOGO_DESC).attributes(key("constraints").value("Optional")), fieldWithPath("[].config.branding.footerLegalText").description(BRANDING_FOOTER_LEGAL_TEXT_DESC).attributes(key("constraints").value("Optional")), fieldWithPath("[].config.branding.footerLinks.*").description(BRANDING_FOOTER_LINKS_DESC).attributes(key("constraints").value("Optional")),
@Test public void apiCodeRequest() throws Exception { resetMarissaPassword(userProvisioning); String cfAccessToken = MockMvcUtils.getUserOAuthAccessToken( mockMvc, "cf", "", UaaTestAccounts.DEFAULT_USERNAME, UaaTestAccounts.DEFAULT_PASSWORD, "uaa.user" ); MockHttpServletRequestBuilder get = get("/oauth/authorize") .header("Authorization", "Bearer " + cfAccessToken) .param(RESPONSE_TYPE, "code") .param(CLIENT_ID, "login") .param(REDIRECT_URI, "http://localhost/redirect/cf") .param(STATE, new RandomValueStringGenerator().generate()); Snippet requestParameters = requestParameters( responseTypeParameter.description("Space-delimited list of response types. Here, `code` for requesting an authorization code for an access token, as per OAuth spec"), clientIdParameter, redirectParameter, parameterWithName(STATE).description("any random string to be returned in the Location header as a query parameter, used to achieve per-request customization").attributes(key("constraints").value("Required"), key("type").value(STRING)) ); mockMvc.perform(get) .andExpect(status().isFound()) .andDo(document("{ClassName}/{methodName}", requestParameters).snippets(requestHeaders( headerWithName("Authorization").description("Bearer token containing uaa.user scope - the authentication for this user")))); }
parameterWithName("filter").required().description("SCIM filter for users over `userName`, `id`, and `origin`, using only the `eq` comparison operator").attributes(key("type").value(STRING)), parameterWithName("sortOrder").optional("ascending").description("sort by username in `ascending` or `descending` order").attributes(key("type").value(STRING)), parameterWithName("startIndex").optional("1").description("display paged results beginning at specified index").attributes(key("type").value(NUMBER)), parameterWithName("count").optional("100").description("number of results to return per page").attributes(key("type").value(NUMBER)), parameterWithName("includeInactive").optional("false").description("include users from inactive identity providers").attributes(key("type").value(BOOLEAN)) );
fieldWithPath("emails").attributes(key("constraints").value("Required")).description("User is invited by providing an email address. More than one email addresses can be provided.") ); parameterWithName("client_id").attributes(key("constraints").value("Optional"), key("type").value(STRING)).description("A unique string representing the registration information provided by the client"), parameterWithName("redirect_uri").attributes(key("constraints").value("Required"), key("type").value(STRING)).description("The user will be redirected to this uri, when user accepts the invitation. The redirect_uri will be validated against allowed redirect_uri for the client.") );
parameterWithName("token").description("The token").attributes(key("constraints").value("Required"), key("type").value(STRING)), parameterWithName("scopes").description("String of comma-separated scopes, for checking presence of scopes on the token").attributes(key("constraints").value("Optional"), key("type").value(ARRAY)) );
@Test void getUserVerificationLink() throws Exception { String accessToken = testClient.getClientCredentialsOAuthAccessToken("admin", "adminsecret", "uaa.admin"); String email = "joel" + new RandomValueStringGenerator().generate() + "@example.com"; ScimUser joel = new ScimUser(null, email, "Joel", "D'sa"); joel.setVerified(false); joel.addEmail(email); joel = userProvisioning.createUser(joel, "pas5Word", IdentityZoneHolder.get().getId()); MockHttpServletRequestBuilder get = RestDocumentationRequestBuilders.get("/Users/{userId}/verify-link", joel.getId()) .header("Authorization", "Bearer " + accessToken) .param("redirect_uri", "http://redirect.to/app") .accept(APPLICATION_JSON); Snippet requestHeaders = requestHeaders(headerWithName("Authorization").description("The bearer token, with a pre-amble of `Bearer`"), IDENTITY_ZONE_ID_HEADER, IDENTITY_ZONE_SUBDOMAIN_HEADER); Snippet requestParameters = requestParameters(parameterWithName("redirect_uri").required().description("Location where the user will be redirected after verifying by clicking the verification link").attributes(key("type").value(STRING))); Snippet responseFields = responseFields(fieldWithPath("verify_link").description("Location the user must visit and authenticate to verify")); Snippet pathParameters = pathParameters( RequestDocumentation.parameterWithName("userId").description("The ID of the user to verify") ); mockMvc.perform(get) .andDo(print()) .andExpect(status().isOk()) .andDo(document("{ClassName}/{methodName}", preprocessResponse(prettyPrint()), pathParameters, requestHeaders, requestParameters, responseFields)) ; }